|
|
@ -180,30 +180,32 @@ if True:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<AFTER> {
|
|
|
|
<AFTER> {
|
|
|
|
|
|
|
|
|
|
|
|
/* Delimiters. */
|
|
|
|
/* Delimiters. */
|
|
|
|
{LineBreak} { yybegin(YYINITIAL); currIndent = 0;indentErrorUnchecked = true; return symbol(ChocoPyTokens.NEWLINE);}
|
|
|
|
{LineBreak} { yybegin(YYINITIAL); currIndent = 0;indentErrorUnchecked = true; return symbol(ChocoPyTokens.NEWLINE);}
|
|
|
|
":" { return symbol(ChocoPyTokens.COLON); }
|
|
|
|
":" { return symbol(ChocoPyTokens.COLON); }
|
|
|
|
"," { return symbol(ChocoPyTokens.COMMA); }
|
|
|
|
"," { return symbol(ChocoPyTokens.COMMA); }
|
|
|
|
|
|
|
|
|
|
|
|
/* Literals. */
|
|
|
|
/* Literals. */
|
|
|
|
{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); }
|
|
|
@ -227,47 +229,51 @@ if True:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Operators. */
|
|
|
|
/* Operators. */
|
|
|
|
"+" { return symbol(ChocoPyTokens.PLUS); }
|
|
|
|
"+" { return symbol(ChocoPyTokens.PLUS); }
|
|
|
|
"-" { return symbol(ChocoPyTokens.MINUS); }
|
|
|
|
"-" { return symbol(ChocoPyTokens.MINUS); }
|
|
|
|
"*" { return symbol(ChocoPyTokens.MUL); }
|
|
|
|
"*" { return symbol(ChocoPyTokens.MUL); }
|
|
|
|
"//" { return symbol(ChocoPyTokens.DIV); }
|
|
|
|
"//" { return symbol(ChocoPyTokens.DIV); }
|
|
|
|
"/" { return symbol(ChocoPyTokens.DIV); } //Accroding to manual, chocopy don't have fp division, '/', '//' should be integr division
|
|
|
|
"/" { return symbol(ChocoPyTokens.DIV); } //Accroding to manual, chocopy don't have fp division, '/', '//' should be integr division
|
|
|
|
"%" { return symbol(ChocoPyTokens.MOD); }
|
|
|
|
"%" { return symbol(ChocoPyTokens.MOD); }
|
|
|
|
">" { return symbol(ChocoPyTokens.GT); }
|
|
|
|
">" { return symbol(ChocoPyTokens.GT); }
|
|
|
|
"<" { return symbol(ChocoPyTokens.LT); }
|
|
|
|
"<" { return symbol(ChocoPyTokens.LT); }
|
|
|
|
"==" { return symbol(ChocoPyTokens.EQUAL); }
|
|
|
|
"==" { return symbol(ChocoPyTokens.EQUAL); }
|
|
|
|
"!=" { return symbol(ChocoPyTokens.NEQ); }
|
|
|
|
"!=" { return symbol(ChocoPyTokens.NEQ); }
|
|
|
|
">=" { return symbol(ChocoPyTokens.GEQ); }
|
|
|
|
">=" { return symbol(ChocoPyTokens.GEQ); }
|
|
|
|
"<=" { return symbol(ChocoPyTokens.LEQ); }
|
|
|
|
"<=" { return symbol(ChocoPyTokens.LEQ); }
|
|
|
|
"=" { return symbol(ChocoPyTokens.ASSIGN); }
|
|
|
|
"=" { return symbol(ChocoPyTokens.ASSIGN); }
|
|
|
|
"and" { return symbol(ChocoPyTokens.AND); }
|
|
|
|
"and" { return symbol(ChocoPyTokens.AND); }
|
|
|
|
"or" { return symbol(ChocoPyTokens.OR); }
|
|
|
|
"or" { return symbol(ChocoPyTokens.OR); }
|
|
|
|
"not" { return symbol(ChocoPyTokens.NOT); }
|
|
|
|
"not" { return symbol(ChocoPyTokens.NOT); }
|
|
|
|
"." { return symbol(ChocoPyTokens.DOT); }
|
|
|
|
"." { return symbol(ChocoPyTokens.DOT); }
|
|
|
|
"(" { return symbol(ChocoPyTokens.LPAR); }
|
|
|
|
"(" { return symbol(ChocoPyTokens.LPAR); }
|
|
|
|
")" { return symbol(ChocoPyTokens.RPAR); }
|
|
|
|
")" { return symbol(ChocoPyTokens.RPAR); }
|
|
|
|
"[" { return symbol(ChocoPyTokens.LBR); }
|
|
|
|
"[" { return symbol(ChocoPyTokens.LBR); }
|
|
|
|
"]" { return symbol(ChocoPyTokens.RBR); }
|
|
|
|
"]" { return symbol(ChocoPyTokens.RBR); }
|
|
|
|
"->" { return symbol(ChocoPyTokens.ARROW); }
|
|
|
|
"->" { return symbol(ChocoPyTokens.ARROW); }
|
|
|
|
"is" { return symbol(ChocoPyTokens.IS); }
|
|
|
|
"is" { return symbol(ChocoPyTokens.IS); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*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.*/ }
|
|
|
|
|
|
|
|
"\"" {yybegin(AFTER); return symbolFactory.newSymbol(ChocoPyTokens.terminalNames[ChocoPyTokens.STRING], ChocoPyTokens.STRING,
|
|
|
|
\\$ { /*'\' at the end of line, do nothing.*/ }
|
|
|
|
new ComplexSymbolFactory.Location(str_l, str_c),
|
|
|
|
|
|
|
|
new ComplexSymbolFactory.Location(yyline + 1,yycolumn + yylength()),
|
|
|
|
"\"" { yybegin(AFTER); return symbolFactory.newSymbol(ChocoPyTokens.terminalNames[ChocoPyTokens.STRING], ChocoPyTokens.STRING,
|
|
|
|
currString);} // accepted a ", return to AFTER state
|
|
|
|
new ComplexSymbolFactory.Location(str_l, str_c),
|
|
|
|
|
|
|
|
new ComplexSymbolFactory.Location(yyline + 1,yycolumn + yylength()),
|
|
|
|
|
|
|
|
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); }
|
|
|
|