ID:

Anthony Lopez-Gagnon

Spec :

Dev Front-end

Alias :

KroNos Aelion

DEV

FRONT-END

# reads a node from standard input # PROC read node = REF NODE: BEGIN REF NODE result := NIL; # parses a string from line and stores it in a string in the text array # # - if it is not already present in the specified textElement list. # # returns the position of the string in the text array # PROC read string = ( REF[]STRING text list, CHAR terminator )INT: BEGIN # get the text of the string # STRING str := line[ l pos ]; l pos +:= 1; WHILE IF l pos <= UPB line THEN line[ l pos ] /= terminator ELSE FALSE FI DO str +:= line[ l pos ]; l pos +:= 1 OD; IF l pos > UPB line THEN gen error( "Unterminated String in node file: (" + line + ")." ) FI; # attempt to find the text in the list of strings/identifiers # INT t pos := LWB text list; BOOL found := FALSE; INT result := LWB text list - 1; FOR t pos FROM LWB text list TO UPB text list WHILE NOT found DO IF found := text list[ t pos ] = str THEN # found the string # result := t pos ELIF text list[ t pos ] = "" THEN # have an empty slot for ther string # found := TRUE; text list[ t pos ] := str; result := t pos FI OD; IF NOT found THEN gen error( "Out of string space." ) FI; result END # read string # ; # gets an integer from the line - no checks for valid digits # PROC read integer = INT: BEGIN INT n := 0; WHILE line[ l pos ] /= " " DO ( n *:= 10 ) +:= ( ABS line[ l pos ] - ABS "0" ); l pos +:= 1 OD; n END # read integer # ; STRING line, name; INT l pos := 1, nd type := -1; read( ( line, newline ) ); line +:= " "; # get the node type name # WHILE line[ l pos ] = " " DO l pos +:= 1 OD; name := ""; WHILE IF l pos > UPB line THEN FALSE ELSE line[ l pos ] /= " " FI DO name +:= line[ l pos ]; l pos +:= 1 OD; # determine the node type # nd type := LWB nd name; IF name /= ";" THEN # not a null node # WHILE IF nd type <= UPB nd name THEN name /= nd name[ nd type ] ELSE FALSE FI DO nd type +:= 1 OD; IF nd type > UPB nd name THEN gen error( "Malformed node: (" + line + ")." ) FI; # handle the additional parameter for identifier/string/integer, or sub-nodes for operator nodes # IF nd type = ninteger OR nd type = nidentifier OR nd type = nstring THEN WHILE line[ l pos ] = " " DO l pos +:= 1 OD; IF nd type = ninteger THEN result := operand node( nd type, read integer ) ELIF nd type = nidentifier THEN result := operand node( nd type, read string( identifiers, " " ) ) ELSE # nd type = nString # result := operand node( nd type, read string( strings, """" ) ) FI ELSE # operator node # } // Rcc.Sample namespace

scroll

Swipe up