blob: 110afb78277fbad740a51f946ca95cdf6d17ffe2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
%{
#include <iostream>
#include "node.hpp"
#include "grammar.hpp"
#define YYLEX grammarlex
#define SAVE_TOKEN grammarlval.string = new std::string( yytext, yyleng )
#define DEBUG( what ) std::cerr << "DEBUG: " << what << " '" << yytext << "'" << std::endl
#define TOKEN( t ) ( grammarlval.token = t )
%}
%%
[ \t\n] ;
[a-zA-Z_][a-zA-Z0-9_]* DEBUG( "TIDENTIFIER" ); SAVE_TOKEN; return TIDENTIFIER;
[0-9]+ DEBUG( "TINTEGER" ); SAVE_TOKEN; return TINTEGER;
"(" DEBUG( "TLPAREN" ); return TOKEN( TLPAREN );
")" DEBUG( "TRPAREN" ); return TOKEN( TRPAREN );
"{" DEBUG( "TLBRACE" ); return TOKEN( TLBRACE );
"}" DEBUG( "TRBRACE" ); return TOKEN( TRBRACE );
"=" DEBUG( "TEQUAL" ); return TOKEN( TEQUAL );
"*" DEBUG( "TMUL" ); return TOKEN( TMUL );
"+" DEBUG( "TPLUS" ); return TOKEN( TPLUS );
"," DEBUG( "TCOMMA" ); return TOKEN( TCOMMA );
"//".* // ignore comments;
. std::cerr << "ERROR: Unknown token '" << yytext << "'" << std::endl; yyterminate( );
%%
int grammarwrap( void )
{
return 1;
}
|