set yyin, add default program rule
git-svn-id: svn://anubis/misc/llvm@65 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
parent
b33303d296
commit
88735f6e40
@ -5,8 +5,8 @@
|
||||
|
||||
%%
|
||||
0b[01]+ return BIN_NUMBER;
|
||||
0x[0-9A-Fa-f] return HEX_NUMBER;
|
||||
0[0-9]* return OCT_NUMBER;
|
||||
0x[0-9A-Fa-f]+ return HEX_NUMBER;
|
||||
0[0-7]* return OCT_NUMBER;
|
||||
[1-9][0-9]* return DEC_NUMBER;
|
||||
\n /* ignore newlines */
|
||||
[ \t\v] /* ignore whitespace */
|
||||
|
11
jlc/jl.y
11
jlc/jl.y
@ -2,6 +2,8 @@
|
||||
%{
|
||||
#include <stdio.h>
|
||||
|
||||
extern FILE * yyin;
|
||||
|
||||
void yyerror(const char * str)
|
||||
{
|
||||
fprintf(stderr, "error: %s\n", str);
|
||||
@ -12,8 +14,12 @@ int yywrap()
|
||||
return 1;
|
||||
}
|
||||
|
||||
main()
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
if (argc > 0)
|
||||
{
|
||||
yyin = fopen(argv[1], "r");
|
||||
}
|
||||
yyparse();
|
||||
}
|
||||
|
||||
@ -23,6 +29,9 @@ main()
|
||||
|
||||
%%
|
||||
|
||||
program: /* empty */
|
||||
| number program { printf("Saw a number\n"); }
|
||||
|
||||
number: BIN_NUMBER
|
||||
| OCT_NUMBER
|
||||
| DEC_NUMBER
|
||||
|
Loading…
x
Reference in New Issue
Block a user