-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from romildo/maven
Integrates CUP and JFlex
- Loading branch information
Showing
6 changed files
with
127 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package parse; | ||
|
||
terminal LITINT; | ||
terminal PLUS, MINUS, TIMES, DIV; | ||
terminal LPAREN, RPAREN; | ||
|
||
non terminal exp; | ||
|
||
start with exp; | ||
|
||
exp ::= | ||
; |
12 changes: 9 additions & 3 deletions
12
src/main/java/LexerDriver.java → src/main/java/main/LexerDriver.java
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
package main; | ||
|
||
import java.io.InputStreamReader; | ||
import java.io.Reader; | ||
import java_cup.runtime.Symbol; | ||
|
||
import parse.Yylex; | ||
import parse.sym; | ||
|
||
public class LexerDriver { | ||
|
||
public static void main(String[] args) throws Exception { | ||
Reader input = new InputStreamReader(System.in); | ||
Yylex lexer = new Yylex(input); | ||
int tok; | ||
Symbol tok; | ||
do { | ||
tok = lexer.yylex(); | ||
tok = lexer.next_token(); | ||
System.out.println(tok); | ||
} while (tok != lexer.YYEOF); | ||
} while (tok.sym != sym.EOF ); | ||
} | ||
|
||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
package parse; | ||
|
||
import java_cup.runtime.Symbol; | ||
|
||
%% | ||
|
||
%public | ||
%integer | ||
%cup | ||
|
||
%% | ||
|
||
[ \t\f\n\r]+ { /* skip */ } | ||
|
||
[0-9]+ ("." [0-9]+)? { return 10; } | ||
|
||
"+" { return 21; } | ||
"-" { return 22; } | ||
"*" { return 23; } | ||
"/" { return 24; } | ||
[0-9]+ ("." [0-9]+)? { return new Symbol(sym.LITINT, yytext()); } | ||
|
||
"(" { return 31; } | ||
")" { return 32; } | ||
"+" { return new Symbol(sym.PLUS); } | ||
"-" { return new Symbol(sym.MINUS); } | ||
"*" { return new Symbol(sym.TIMES); } | ||
"/" { return new Symbol(sym.DIV); } | ||
"(" { return new Symbol(sym.LPAREN); } | ||
")" { return new Symbol(sym.RPAREN); } | ||
|
||
. { System.out.printf("unexpected char |%s|\n", yytext()); } |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
12 * (453.2 - 140.3) / 2 |