"/*"{char c; int num = 1; int n = 0; while( num ){
c = input();
n ++; if( c =='/'){ while(( c = input())=='/') ; if( c =='*')
num ++; } elseif( c =='*'){ while(( c = input())=='*') ; if( c =='/')
num --; } if( c =='\n')
EM_newline(); }
adjust();
charPos += n; continue; }
测试结果:
[heixia@localhost chap2]$./lextest test1.tig
LET 43
TYPE 48
ID 52 arrtype
EQ 59
ARRAY 60
OF 65
ID 67 int
VAR 72
ID 75 arr1
COLON 79
ID 80 arrtype
ASSIGN 87
ID 89 arrtype
LBRACK 96 INT 97 10
RBRACK 99
OF 100 INT 102 0
IN 104
ID 108 arr1
END 113
原文件:
/* an array type and an array variable*/
let
type arrtype = array of int
var arr1:arrtype := arrtype [10] of 0
in
arr1
end