Added keyword reservation to Syntax

main
channa 10 months ago
parent bbb3b5f55a
commit b35a7c9822

@ -1,7 +1,6 @@
module Syntax module Syntax
extend lang::std::Whitespace; extend lang::std::Whitespace;
extend lang::std::Id;
extend lang::std::ASCII; extend lang::std::ASCII;
/* /*
@ -108,7 +107,7 @@ syntax Lhs = Id ("[" Expr "]")?
syntax SubProgCall = 'readln'"(" LhsList ")" syntax SubProgCall = 'readln'"(" LhsList ")"
| 'writeln'"(" ExprList ")" | 'writeln'"(" ExprList ")"
> Id \ 'writeln' \ 'readln' \ 'skip' ("(" ExprList ")")? > Id ("(" ExprList ")")?
; ;
syntax ExprList = Expr ("," Expr)* syntax ExprList = Expr ("," Expr)*
@ -138,6 +137,14 @@ syntax Expr = "(" Expr ")"
/* /*
Basic lexical constructs. Basic lexical constructs.
*/ */
keyword Reserved = 'program' | 'const' | 'var' | 'array' | 'of' | 'integer'
| 'real' | 'function' | 'procedure' | 'begin' | 'end'
| 'skip' | 'if' | 'then' | 'else' | 'while' | 'do' | 'not'
| 'or' | 'and' | 'readln' | 'writeln'
;
lexical Id = ([a-z A-Z 0-9 _] !<< [a-z A-Z][a-z A-Z 0-9 _]* !>> [a-z A-Z 0-9 _]) \ Reserved
;
lexical Relop = "\<"|"\<="|"\>"|"\>="|"="|"\<\>"; lexical Relop = "\<"|"\<="|"\>"|"\>="|"="|"\<\>";
lexical Number = Digit+ lexical Number = Digit+
| Digit* "." Digit+ | Digit* "." Digit+

@ -1,6 +1,7 @@
module Test module Test
import ParseTree; import ParseTree;
import Exception;
import Syntax; import Syntax;
import IO; import IO;
@ -17,9 +18,8 @@ void main() {
*/ */
start[Program] runSyntaxTestOn(loc file) { start[Program] runSyntaxTestOn(loc file) {
println("Parsing: <file>"); println("Parsing: <file>");
pt = parse(#start[Program], file); return parse(#start[Program], file);
return pt;
} }
list[loc] getFilesIn(loc dir) { list[loc] getFilesIn(loc dir) {

Loading…
Cancel
Save