added print table functionality to main in grammar.y with custom EOF input in '!'
This commit is contained in:
22
grammar.y
22
grammar.y
@ -8,7 +8,9 @@
|
||||
extern int yylex(void);
|
||||
void yyerror(const char *err);
|
||||
extern char* yytext;
|
||||
extern int yychar;
|
||||
extern int yychar;
|
||||
SymbolTable * st;
|
||||
|
||||
%}
|
||||
|
||||
%token ID 101
|
||||
@ -59,28 +61,28 @@
|
||||
%token COMMENT 700
|
||||
%%
|
||||
|
||||
input: /*empty for now*/
|
||||
start: /*empty for now*/
|
||||
OPTIONAL;
|
||||
|
||||
OPTIONAL:
|
||||
L_BRACKET {printf("success");};
|
||||
// B : '{'{CreateScope(cur,line,column)} E '}'; //Braced Expressions can have braces removed to get regular expressions
|
||||
// D : '[' l ']'; //Declaration Lists Brackets can be taken out to get a list of Declarations
|
||||
// E : Maybe_D U; //An expression can start with an optional D followed by an undeclared segment
|
||||
// Maybe_D : D
|
||||
// | ; //Either D or not
|
||||
//l : A ';' l;
|
||||
// | ; //a declaration list can either be empty or be an assignment followed by a semi-colon and another list
|
||||
|
||||
//
|
||||
%%
|
||||
|
||||
void yyerror(const char *err) {
|
||||
fprintf(stderr, "Error: %s\n", err);
|
||||
}
|
||||
|
||||
int main() {
|
||||
st=CreateScope(NULL,1,1);
|
||||
int a;
|
||||
while (a = yyparse()){
|
||||
while ((a = yyparse()) != EOF){
|
||||
printf("%d = a: yytext = %s: yychar = %d\n", a, yytext, yychar);
|
||||
if(yytext[0] == '!'){
|
||||
print_symbol_table(getAncestor(st),stdout);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user