2014-10-16 15:30:59 +02:00
|
|
|
%include {
|
|
|
|
#include <assert.h>
|
|
|
|
#include <cstdlib>
|
2014-10-17 17:43:57 +02:00
|
|
|
#include "token_def.h"
|
2014-10-16 15:30:59 +02:00
|
|
|
}
|
|
|
|
%syntax_error { printf("Lemon syntax error\n"); }
|
|
|
|
|
2014-10-17 17:43:57 +02:00
|
|
|
%token_type {LexerToken*}
|
|
|
|
%extra_argument { float* result }
|
2014-10-16 15:30:59 +02:00
|
|
|
|
2014-10-17 17:43:57 +02:00
|
|
|
%type expr {float}
|
2014-10-16 15:30:59 +02:00
|
|
|
%left PLUS MINUS .
|
|
|
|
|
|
|
|
start ::= prog.
|
|
|
|
|
|
|
|
prog ::= prog print NL .
|
|
|
|
prog ::= prog print .
|
|
|
|
prog ::= .
|
|
|
|
|
|
|
|
print ::= expr(a) . { *result = a; }
|
|
|
|
|
2014-10-17 17:43:57 +02:00
|
|
|
expr(a) ::= NUMBER(b) . { a = b->fval; }
|
2014-10-16 15:30:59 +02:00
|
|
|
expr(a) ::= expr(b) PLUS expr(c) . { a = b + c; }
|