Created
May 13, 2011 06:23
-
-
Save jedp/970079 to your computer and use it in GitHub Desktop.
Jison grammar to convert numerals into an integer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Jison grammar for converting numerals into an integer */ | |
/* The lexical analyzer | |
How we break things up into tokens */ | |
%lex | |
%% | |
[0-9]+ return 'INT' | |
"-" return '-' | |
<<EOF>> return 'EOF' | |
. return 'TOTAL_DISASTER' | |
/lex | |
%left UMINUS | |
/* The grammar | |
How we figure out what the tokens mean */ | |
%start grammar | |
%% | |
grammar | |
: integer EOF { return $integer; } | |
| EOF { return null; } | |
; | |
integer | |
: INT { $$ = Number(yytext); } | |
| '-' integer %prec UMINUS { $$ = -$2; } | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment