diff --git a/src/main/cup/chocopy/pa1/ChocoPy.cup b/src/main/cup/chocopy/pa1/ChocoPy.cup index 0bc9dd6..0585cf7 100644 --- a/src/main/cup/chocopy/pa1/ChocoPy.cup +++ b/src/main/cup/chocopy/pa1/ChocoPy.cup @@ -145,8 +145,8 @@ action code {: terminal NEWLINE; terminal String PLUS; terminal String MINUS; -terminal String MULTIPLY; -terminal String DIVIDE; +terminal String MUL; +terminal String DIV; terminal String NAMES; terminal Integer NUMBER; diff --git a/src/main/jflex/chocopy/pa1/ChocoPy.jflex b/src/main/jflex/chocopy/pa1/ChocoPy.jflex index e90072a..ebcec10 100644 --- a/src/main/jflex/chocopy/pa1/ChocoPy.jflex +++ b/src/main/jflex/chocopy/pa1/ChocoPy.jflex @@ -8,7 +8,7 @@ import java.util.ArrayList; %unicode %line %column -%states AFTER +%states AFTER, STR %class ChocoPyLexer %public @@ -33,6 +33,7 @@ import java.util.ArrayList; /** Producer of token-related values for the parser. */ final ComplexSymbolFactory symbolFactory = new ComplexSymbolFactory(); private int currIndent = 0; + private int currString = ""; private ArrayList stack = new ArrayList(20); /** Return a terminal symbol of syntactic category TYPE and no * semantic value at the current source location. */ @@ -67,7 +68,7 @@ WhiteSpace = [ \t] LineBreak = \r|\n|\r\n IntegerLiteral = 0|[1-9][0-9]* -StringLiteral = \"([^\"\\]|(\\\")|(\\t)|(\\r)|(\\n)|(\\\\))*\" +StringLiteral = ([^\"\\]|(\\\")|(\\t)|(\\r)|(\\n)|(\\\\))* Names = (_|[a-z]|[A-Z])(_|[a-z]|[A-Z])* Comments = #[^\r\n]* %% @@ -112,7 +113,8 @@ Comments = #[^\r\n]* /* Literals. */ {IntegerLiteral} { return symbol(ChocoPyTokens.NUMBER, Integer.parseInt(yytext())); } - {StringLiteral} { return symbol(ChocoPyTokens.STRING, yytext());} +// {StringLiteral} { return symbol(ChocoPyTokens.STRING, yytext());} + "\"" {yystart(STR); currString = "";} "False" { return symbol(ChocoPyTokens.BOOL, false); } "True" { return symbol(ChocoPyTokens.BOOL, true); } "None" { return symbol(ChocoPyTokens.NONE); } @@ -180,7 +182,10 @@ Comments = #[^\r\n]* /* Comment. */ {Comments} { /* ignore */ } } - +{ + {StringLiteral} {currString+=yytext();} + "\"" {yybegin(AFTER); return symbol(ChocoPyTokens.STRING, currString);} +} <> { return symbol(ChocoPyTokens.EOF); } /* Error fallback. */