Created
September 21, 2011 21:45
-
-
Save markmarch/1233408 to your computer and use it in GitHub Desktop.
Revisions
-
Xiaoming Jia revised this gist
Sep 21, 2011 . 1 changed file with 11 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,13 @@ * void means do not create AST * / means ordered alternative */ module Sample; header { import java.util.*;} body { public static final Set<String> KEYWORDS = new HashSet<String>(Arrays.asList("if", "else"));} public void program = WS statement EOF; void statement = IF LPAREN expr RPAREN @@ -35,4 +42,7 @@ void REL_OP = ("<="/"<"/">="/">") WS; // order alternation, cause "<" is the prefix of "<=" void ID = i:ID_INTERNAL WS &{!KEYWORDS.contains(i)}; void ID_INTERNAL = [a-zA-Z][a-zA-Z0-9] -
Xiaoming Jia revised this gist
Sep 21, 2011 . 1 changed file with 8 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ * void means do not create AST * / means ordered alternative */ public void program = WS statement EOF; void statement = IF LPAREN expr RPAREN statement ELSE statement @@ -29,4 +29,10 @@ !: negative predicate neither predicate will actually consume the character **/ void COMMENT = "/*"(!"*"_/"*"!"/")˚"*/" void EOF = !_; void REL_OP = ("<="/"<"/">="/">") WS; // order alternation, cause "<" is the prefix of "<=" void ID = :ID_INTERNAL WS -
Xiaoming Jia revised this gist
Sep 21, 2011 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,4 +25,8 @@ // whitespace void WS = ([ \t\n\f]/COMMENT)˚ /** &: positive predicate !: negative predicate neither predicate will actually consume the character **/ void COMMENT = "/*"(!"*"_/"*"!"/")˚"*/" -
Xiaoming Jia revised this gist
Sep 21, 2011 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,6 +23,6 @@ void SEMI = ";" // whitespace void WS = ([ \t\n\f]/COMMENT)˚ void COMMENT = "/*"(!"*"_|"*"!"/")˚"*/" -
Xiaoming Jia revised this gist
Sep 21, 2011 . 1 changed file with 28 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +1,28 @@ /** * Syntax Analysis production * void means do not create AST * / means ordered alternative */ public void program = statement; void statement = IF LPAREN expr RPAREN statement ELSE statement / IF LPAREN expr RPAREN statement / SEMI; void expr = ID REL_OP ID; // simple production , are all void , and will be dropped in AST void IF = "if" void ELSE = "else" void LPAREN = "(" void RPAREN = ")" void SEMI = ";" // whitespace void WS = ([ \t\n\f]/COMMENT) void COMMENT = "/*"(!"*"_| "*/" -
Xiaoming Jia created this gist
Sep 21, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ /* Syntax Analysis production*/ public void program = statement;