creating interpreter with this grammar help
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   zach_evans
Posted On:   Thursday, February 2, 2012 04:08 PM

So I have this set of grammar → program id → | | | | → begin end → | ; → if then else → while do -> id := → print id → → id | constant → < | <= | > | >= | = | /= → | → + | - | * | / I am trying to put this into antlrworks but im getting the error label id conflicts with token with same name grammar program; program : ID compound_statement; statement: if_statement|assignment_statement|while_statement|print_statement|compound_statement; compound_statement: 'begin' stat   More>>

So I have this set of grammar

			

→ program id

→ | | | |

→ begin end

→ | ;

→ if then else

→ while do

-> id :=

→ print id



→ id | constant

→ < | <= | > | >= | = | /=

→ |

→ + | - | * | /



I am trying to put this into antlrworks but im getting the error label id conflicts with token with same name
			
grammar program;

program : ID compound_statement;
statement: if_statement|assignment_statement|while_statement|print_statement|compound_statement;
compound_statement: 'begin' statement_list 'end';
statement_list: statement|statement statement_list;
if_statement: 'if' boolean_expression 'then' statement 'else' statement;
while_statement: 'while' boolean_expression 'do' statement;
assignment_statement: ID = arithmetic_expression;
print_statement: 'print' ID;
boolean_expression: operand relative_op operand;
operand : ID |INT;
relative_op: ' <'|' <='|'>'|'>='|'=='|'/=';
arithmetic_expression: operand|operand arithmetic_op operand;
arithmetic_op: '+'|'-'|'*'|'/';


ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
;

INT : '0'..'9'+
;
WS : ( ' '
| ' '
| '
'
| '
'
) {$channel=HIDDEN;}
;

Do my statements look correct? I am new to antlrworks. Thank you.    <<Less
About | Sitemap | Contact