|
|
@ -180,6 +180,8 @@ if True:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<AFTER> {
|
|
|
|
<AFTER> {
|
|
|
|
|
|
|
|
|
|
|
|
/* Delimiters. */
|
|
|
|
/* Delimiters. */
|
|
|
@ -191,19 +193,19 @@ if True:
|
|
|
|
{IntegerLiteral} { return symbol(ChocoPyTokens.NUMBER,
|
|
|
|
{IntegerLiteral} { return symbol(ChocoPyTokens.NUMBER,
|
|
|
|
Integer.parseInt(yytext())); }
|
|
|
|
Integer.parseInt(yytext())); }
|
|
|
|
|
|
|
|
|
|
|
|
"\"" {yybegin(STR); str_l = yyline + 1; str_c = yycolumn + 1; currString = "";} //Start taking a string when see a "
|
|
|
|
"\"" { yybegin(STR); str_l = yyline + 1; str_c = yycolumn + 1; currString = ""; } //Start taking a string when see a "
|
|
|
|
"False" { return symbol(ChocoPyTokens.BOOL, false); }
|
|
|
|
"False" { return symbol(ChocoPyTokens.BOOL, false); }
|
|
|
|
"True" { return symbol(ChocoPyTokens.BOOL, true); }
|
|
|
|
"True" { return symbol(ChocoPyTokens.BOOL, true); }
|
|
|
|
"None" { return symbol(ChocoPyTokens.NONE); }
|
|
|
|
"None" { return symbol(ChocoPyTokens.NONE); }
|
|
|
|
|
|
|
|
|
|
|
|
/*Keywords*/
|
|
|
|
/*Keywords*/
|
|
|
|
"if" {return symbol(ChocoPyTokens.IF);}
|
|
|
|
"if" { return symbol(ChocoPyTokens.IF); }
|
|
|
|
"else" {return symbol(ChocoPyTokens.ELSE);}
|
|
|
|
"else" { return symbol(ChocoPyTokens.ELSE); }
|
|
|
|
"elif" {return symbol(ChocoPyTokens.ELIF);}
|
|
|
|
"elif" { return symbol(ChocoPyTokens.ELIF); }
|
|
|
|
"while" {return symbol(ChocoPyTokens.WHILE);}
|
|
|
|
"while" { return symbol(ChocoPyTokens.WHILE); }
|
|
|
|
"class" {return symbol(ChocoPyTokens.CLASS);}
|
|
|
|
"class" { return symbol(ChocoPyTokens.CLASS); }
|
|
|
|
"def" {return symbol(ChocoPyTokens.DEF);}
|
|
|
|
"def" { return symbol(ChocoPyTokens.DEF); }
|
|
|
|
"lambda" {return symbol(ChocoPyTokens.LAMBDA);}
|
|
|
|
"lambda" { return symbol(ChocoPyTokens.LAMBDA); }
|
|
|
|
"as" { return symbol(ChocoPyTokens.AS); }
|
|
|
|
"as" { return symbol(ChocoPyTokens.AS); }
|
|
|
|
"for" { return symbol(ChocoPyTokens.FOR); }
|
|
|
|
"for" { return symbol(ChocoPyTokens.FOR); }
|
|
|
|
"global" { return symbol(ChocoPyTokens.GLOBAL); }
|
|
|
|
"global" { return symbol(ChocoPyTokens.GLOBAL); }
|
|
|
@ -253,21 +255,25 @@ if True:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*Identifiers*/
|
|
|
|
/*Identifiers*/
|
|
|
|
{Identifiers} {return symbol(ChocoPyTokens.ID, yytext());}
|
|
|
|
{Identifiers} { return symbol(ChocoPyTokens.ID, yytext()); }
|
|
|
|
|
|
|
|
|
|
|
|
/* Whitespace. */
|
|
|
|
/* Whitespace. */
|
|
|
|
{WhiteSpace} { /* ignore */ }
|
|
|
|
{WhiteSpace} { /* ignore */ }
|
|
|
|
|
|
|
|
|
|
|
|
/* Comment. */
|
|
|
|
/* Comment. */
|
|
|
|
{Comments} { /* ignore */ }
|
|
|
|
{Comments} { /* ignore */ }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
<STR>{
|
|
|
|
<STR>{
|
|
|
|
{StringLiteral} {currString += yytext();}
|
|
|
|
{StringLiteral} { currString += yytext(); }
|
|
|
|
|
|
|
|
|
|
|
|
\\$ { /*'\' at the end of line, do nothing.*/ }
|
|
|
|
\\$ { /*'\' at the end of line, do nothing.*/ }
|
|
|
|
"\"" {yybegin(AFTER); return symbolFactory.newSymbol(ChocoPyTokens.terminalNames[ChocoPyTokens.STRING], ChocoPyTokens.STRING,
|
|
|
|
|
|
|
|
|
|
|
|
"\"" { yybegin(AFTER); return symbolFactory.newSymbol(ChocoPyTokens.terminalNames[ChocoPyTokens.STRING], ChocoPyTokens.STRING,
|
|
|
|
new ComplexSymbolFactory.Location(str_l, str_c),
|
|
|
|
new ComplexSymbolFactory.Location(str_l, str_c),
|
|
|
|
new ComplexSymbolFactory.Location(yyline + 1,yycolumn + yylength()),
|
|
|
|
new ComplexSymbolFactory.Location(yyline + 1,yycolumn + yylength()),
|
|
|
|
currString);} // accepted a ", return to AFTER state
|
|
|
|
currString); } // accepted a ", return to AFTER state
|
|
|
|
}
|
|
|
|
}
|
|
|
|
<<EOF>> { if(!stack.isEmpty()){ return symbol(ChocoPyTokens.DEDENT, pop());} return symbol(ChocoPyTokens.EOF);}
|
|
|
|
<<EOF>> { if(!stack.isEmpty()){ return symbol(ChocoPyTokens.DEDENT, pop());} return symbol(ChocoPyTokens.EOF); }
|
|
|
|
|
|
|
|
|
|
|
|
/* Error fallback. */
|
|
|
|
/* Error fallback. */
|
|
|
|
[^] { return symbol(ChocoPyTokens.UNRECOGNIZED); }
|
|
|
|
[^] { return symbol(ChocoPyTokens.UNRECOGNIZED); }
|
|
|
|