Dear all,
I bumped into a conflict while writing a small grammar. Would be
great to know why. The problem seems to come from the Assignment
I wish to parse the following:
myfunction (a, b, c){
3 + 10
var z
z = 50 + foo()
}
Parser:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Program : FunctionDefinition * {SPProgram new functions: '1'};
FunctionDefinition :
Id Arguments "{"
ExpressionList
"}" {SPFunction new name: '1'; arguments: ('2' select: [:o| (o
isKindOf: SmaCCToken) not]); expressions: '4'};
Arguments : "(" ArgumentList ")" {'2'};
ArgumentList : ArgumentList "," Id
| Id
| ;
ExpressionList:
Expression ExpressionList
| ;
Expression :
FunctionCall
| VariableDefinition
| Id "=" ExpressionWithValue {SPAssignment new name: '1';
expression: '3'}
| Expression "+" Number {SPAddition new left: '1'; right: '3'}
| Expression "-" Number {SPMinus new left: '1'; right: '3'}
| Number {'1'};
FunctionCall :
Id ArgumentsInCall {SPFunctionCall new name: '1'; arguments: '2'};
ArgumentsInCall :
"(" ArgumentsListInCall ")" {'2' select: [:o| (o isKindOf:
SmaCCToken) not]};
ArgumentsListInCall :
ArgumentsListInCall "," Expression
| Expression
| ;
VariableDefinition :
"var" Id {SPVariableDefinition new name: '2'};
ExpressionWithValue :
ExpressionWithValue "+" Number {SPAddition new left: '1';
right: '3'}
| ExpressionWithValue "-" Number {SPMinus new left: '1';
right: '3'}
| Number {'1'};
Number : <number> {'1' value asNumber} ;
Id : <variable> {'1' value asString} ;
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Scanner:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
<number> : [0-9]+;
<whitespace> : \s+;
<variable> : [a-zA-Z] \w* ;
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Regards,
Alexandre
--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel
http://www.software-artist.eu^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel
http://www.software-artist.eu^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.