I'm using ANTLR and the following grammar:
grammar QuickBasic;
options
{
language = 'CSharp2';
output = AST;
}
parse
: block EOF
;
block
: (labelStatement | labeledStatement | statement)*
;
labelStatement
: label ':' -> ^(label)
;
labeledStatement
: label statement -> ^(label statement)
;
statement
: assignment
;
assignment
: IDENTIFIER '=' value -> ^('=' IDENTIFIER value)
;
value
: (IDENTIFIER | constant)
;
constant
: (STRING | INTEGER | REAL)
;
label
: (ALPHANUMERIC)+
;
IDENTIFIER
: LETTER (ALPHANUMERIC)*
;
REAL
: (INTEGER '.' NATURAL)
;
INTEGER
: ('-')? NATURAL
;
SPACE
: (' ' | '\t' | '\r' | '\n' | '\u000C') {Skip();}
;
STRING
: '"' ('""' | ~'"')* '"'
;
fragment NATURAL
: (DIGIT)+
;
fragment ALPHANUMERIC
: (DIGIT | LETTER)
;
fragment DIGIT
: '0'..'9'
;
fragment LETTER
: ('a'..'z' | 'A'..'Z')
;
With this, I'm trying to parse the folowing file:
PI = 3.141592
CALC:
100 A = 1
What happens next is that line 'CALC:' should be a label, but it tries to parse as a statement, and gives me an error saying mismatched input ':' expecting '='.