Added keyword reservation to Syntax

main
channa 10 months ago
parent bbb3b5f55a
commit b35a7c9822

@ -1,7 +1,6 @@
module Syntax
extend lang::std::Whitespace;
extend lang::std::Id;
extend lang::std::ASCII;
/*
@ -108,7 +107,7 @@ syntax Lhs = Id ("[" Expr "]")?
syntax SubProgCall = 'readln'"(" LhsList ")"
| 'writeln'"(" ExprList ")"
> Id \ 'writeln' \ 'readln' \ 'skip' ("(" ExprList ")")?
> Id ("(" ExprList ")")?
;
syntax ExprList = Expr ("," Expr)*
@ -138,10 +137,18 @@ syntax Expr = "(" Expr ")"
/*
Basic lexical constructs.
*/
lexical Relop = "\<"|"\<="|"\>"|"\>="|"="|"\<\>";
lexical Number = Digit+
| Digit* "." Digit+
;
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 Number = Digit+
| Digit* "." Digit+
;
/*
A comment is anything between a "{" and a "}"
*/

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

Loading…
Cancel
Save