Changes made on Flex to adapt for merging.
This commit is contained in:
@@ -34,6 +34,7 @@ import java.util.ArrayList;
|
|||||||
final ComplexSymbolFactory symbolFactory = new ComplexSymbolFactory();
|
final ComplexSymbolFactory symbolFactory = new ComplexSymbolFactory();
|
||||||
private int currIndent = 0; //Current Indentation Level
|
private int currIndent = 0; //Current Indentation Level
|
||||||
private String currString = "";
|
private String currString = "";
|
||||||
|
private int str_l = 0, str_c = 0; //Start location of a string.
|
||||||
/*A stack that keeps track of the spaces in each Indentation Level*/
|
/*A stack that keeps track of the spaces in each Indentation Level*/
|
||||||
private ArrayList<Integer> stack = new ArrayList<Integer>(20);
|
private ArrayList<Integer> stack = new ArrayList<Integer>(20);
|
||||||
/** Return a terminal symbol of syntactic category TYPE and no
|
/** Return a terminal symbol of syntactic category TYPE and no
|
||||||
@@ -45,6 +46,7 @@ import java.util.ArrayList;
|
|||||||
/** Return a terminal symbol of syntactic category TYPE and semantic
|
/** Return a terminal symbol of syntactic category TYPE and semantic
|
||||||
* value VALUE at the current source location. */
|
* value VALUE at the current source location. */
|
||||||
private Symbol symbol(int type, Object value) {
|
private Symbol symbol(int type, Object value) {
|
||||||
|
//System.out.println(yytext() + ChocoPyTokens.terminalNames[type]);
|
||||||
return symbolFactory.newSymbol(ChocoPyTokens.terminalNames[type], type,
|
return symbolFactory.newSymbol(ChocoPyTokens.terminalNames[type], type,
|
||||||
new ComplexSymbolFactory.Location(yyline + 1, yycolumn + 1),
|
new ComplexSymbolFactory.Location(yyline + 1, yycolumn + 1),
|
||||||
new ComplexSymbolFactory.Location(yyline + 1,yycolumn + yylength()),
|
new ComplexSymbolFactory.Location(yyline + 1,yycolumn + yylength()),
|
||||||
@@ -134,6 +136,7 @@ if True:
|
|||||||
AFTER state.
|
AFTER state.
|
||||||
*/
|
*/
|
||||||
pop();
|
pop();
|
||||||
|
//System.out.println("dedent");
|
||||||
return symbol(ChocoPyTokens.DEDENT, currIndent);
|
return symbol(ChocoPyTokens.DEDENT, currIndent);
|
||||||
}
|
}
|
||||||
/*Otherwise, we will start dealing with the rest
|
/*Otherwise, we will start dealing with the rest
|
||||||
@@ -146,6 +149,8 @@ if True:
|
|||||||
current level should have, start a new level which will have
|
current level should have, start a new level which will have
|
||||||
`currIndent' indents.
|
`currIndent' indents.
|
||||||
*/
|
*/
|
||||||
|
//System.out.println("indent");
|
||||||
|
|
||||||
push(currIndent);
|
push(currIndent);
|
||||||
return symbol(ChocoPyTokens.INDENT, currIndent);
|
return symbol(ChocoPyTokens.INDENT, currIndent);
|
||||||
}
|
}
|
||||||
@@ -161,7 +166,7 @@ if True:
|
|||||||
/* Literals. */
|
/* Literals. */
|
||||||
{IntegerLiteral} { return symbol(ChocoPyTokens.NUMBER,
|
{IntegerLiteral} { return symbol(ChocoPyTokens.NUMBER,
|
||||||
Integer.parseInt(yytext())); }
|
Integer.parseInt(yytext())); }
|
||||||
"\"" {yybegin(STR); 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); }
|
||||||
@@ -223,7 +228,7 @@ if True:
|
|||||||
|
|
||||||
|
|
||||||
/*Identifiers*/
|
/*Identifiers*/
|
||||||
{Identifiers} {return symbol(ChocoPyTokens.ID, yytext());}
|
{Identifiers} {return symbol(ChocoPyTokens.ID, yytext());}
|
||||||
/* Whitespace. */
|
/* Whitespace. */
|
||||||
{WhiteSpace} { /* ignore */ }
|
{WhiteSpace} { /* ignore */ }
|
||||||
/* Comment. */
|
/* Comment. */
|
||||||
@@ -232,9 +237,12 @@ if True:
|
|||||||
<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 symbol(ChocoPyTokens.STRING, currString);} // accepted a ", return to AFTER state
|
"\"" {yybegin(AFTER); return symbolFactory.newSymbol(ChocoPyTokens.terminalNames[ChocoPyTokens.STRING], ChocoPyTokens.STRING,
|
||||||
|
new ComplexSymbolFactory.Location(str_l, str_c),
|
||||||
|
new ComplexSymbolFactory.Location(yyline + 1,yycolumn + yylength()),
|
||||||
|
currString);} // accepted a ", return to AFTER state
|
||||||
}
|
}
|
||||||
<<EOF>> { 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); }
|
||||||
|
|||||||
Reference in New Issue
Block a user