37 lines
499 B
Plaintext
37 lines
499 B
Plaintext
// Name der Grammatik
|
|
grammar b1;
|
|
|
|
// einfache, feste Tokens
|
|
tokens {
|
|
PLUS = '+' ;
|
|
MINUS = '-' ;
|
|
MULT = '*' ;
|
|
DIV = '/' ;
|
|
}
|
|
|
|
@header {
|
|
package b1;
|
|
}
|
|
|
|
@lexer::header {
|
|
package b1;
|
|
}
|
|
|
|
ausdruck:
|
|
term ( ( PLUS | MINUS ) term )* ;
|
|
|
|
term :
|
|
faktor ( ( MULT | DIV ) faktor )* ;
|
|
|
|
faktor :
|
|
ZAHL ;
|
|
|
|
ZAHL :
|
|
(DIGIT)+ ;
|
|
|
|
WHITESPACE :
|
|
( '\t' | ' ' | '\r' | '\n'| '\u000C' )+
|
|
{ $channel = HIDDEN; } ;
|
|
|
|
fragment DIGIT :
|
|
'0'..'9' ; |