MegaProcessor

Check-in [dc67697206]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:The set of reg-exps in function Process_line now seem to be able to parse the majority of possible source lines into a plausible set of fields. (label, instruction or directive, destination, source ).
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:dc676972066b78423f0cc8c9216345c8ae2ab1ad
User & Date: jos 2015-07-13 23:13:46
Context
2015-07-15
16:20
Incomplete release.. Added some trial stuff. check-in: 2a4605e430 user: jos tags: trunk
2015-07-13
23:13
The set of reg-exps in function Process_line now seem to be able to parse the majority of possible source lines into a plausible set of fields. (label, instruction or directive, destination, source ). check-in: dc67697206 user: jos tags: trunk
2015-07-12
16:47
Moved the test within the loop, to catch comment-only lines that start in columns other than the first as well. check-in: 6073558536 user: jos tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to asm.lua.

6
7
8
9
10
11
12










13
14
15
16
17
18
19
20
21
22
23
24

25
26
27
28
29
30
31





32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
        print( errmsg );
        os.exit(-1);
    end

    return cond ;
end












function ProcessFile( inFileName )
local inFile = Check( io.open(inFileName,"r"),
                    "Can't open file " .. inFileName
                    );

    for l in inFile:lines() do
        ProcessLine( l );
    end
end

function Fields( line )

    local t = {};

    for x in line:gmatch("(%S+)") do
        if( x:sub(1,2) == "//" ) then return 0; end;
        table.insert(t,x)
    end
    return #t, table.unpack(t) ;





end

LineNr = 1;
function ProcessLine( l )
    local n,f1,f2,f3 = Fields(l);
--    local lbl,inst,op = string.match(l,"(%S+)%s+(%S+)%s+");
    print( string.format("%04d:",LineNr), l );
    LineNr = LineNr + 1;
    print( string.format("%d=%s - %s - %s",n,f1,f2,f3) );
end


-- Main line
--
if( not arg[1] ) then
    print("Please supply a filename");







>
>
>
>
>
>
>
>
>
>












>
|
<
|
|
|
|
|
>
>
>
>
>




|
<
|

|







6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

52
53
54
55
56
57
58
59
60
61
        print( errmsg );
        os.exit(-1);
    end

    return cond ;
end

Directive = {
    'db',
    'dl',
    'dm',
    'ds',
    'dw',
    'equ',
    'org'
};


function ProcessFile( inFileName )
local inFile = Check( io.open(inFileName,"r"),
                    "Can't open file " .. inFileName
                    );

    for l in inFile:lines() do
        ProcessLine( l );
    end
end

function Fields( line )
    if( line == "" or line:match("^%s*//") ) then return 0; end;
    local retVal = 0;

    local n, n1, label, instr, dst, src;
    label,n1 = line:match("^(%S+)()");  -- Start of string, (one+ non-space), (empty capture)
    if( label ) then n=n1; retVal = retVal + 1; end
    instr,n1 = line:match("%s+(%S+)%s+()",n); -- one+ space, (one+ non-space), one+ space, (empty capture)
    if( instr ) then n=n1; retVal = retVal + 1; end
    dst,n1 = line:match("([^%s,;]+)()",n);
    if( dst ) then n=n1; retVal = retVal + 1; end
    src,n1  = line:match("[%s,]+([^%s;]+)()",n);
    if( src ) then n=n1; retVal = retVal + 1; end
    return retVal, label, instr, dst, src;
end

LineNr = 1;
function ProcessLine( l )
    local n,f1,f2,f3,f4 = Fields(l);

--    print( string.format("%04d:",LineNr), l );
    LineNr = LineNr + 1;
    print( string.format("%d=%s - %s - %s - %s\n",n,f1,f2,f3,f4) );
end


-- Main line
--
if( not arg[1] ) then
    print("Please supply a filename");