yacc

Statement with no effect warning with GCC and Flex/Bison

When compiling my project with gcc and the -Wall option, I get a warning about a statement with no effect in the non-existant last line of my flex file: Warning: gcc -Wall -O0 -ggdb3 -DNOSUDO -DJOBC -DDEBUG -c lex.yy.c tokenizer.l: In function ‘yylex’: tokenizer.l:179: warning: statement with no effect Shell Command: $ wc -l tokeniz...

Using bison to parse list of elements

Hello, I'm writing a compiler for a shading engine and every worked fine until I reached the statements parsing part. I used an abstract syntax tree defined with classes to do all the work (to simplify typechecking and intermediate code generation).. so I have an ancestor class ASTNode and all descending classes like ASTFloat, ASTExpres...

flex/lex yacc/bison multithreaded environment

Can I use the code generated by flex/bison|lex/yacc in a multithreaded environment ? I'm afraid there are a lot of global variables. How can it be fixed ? ...

Deriving a state machine from a BNF grammar

I am trying to put together a proof of concept of an XSS-safe string interpolation scheme. Given a string with substitutions, "Hello <b>$planetoid</b>!" I want break it into literal portions and substitutions ("Hello<b>" planetoid "</b>!") and then run a state machine left to right over the literal portions. When I reach an interpol...

Left Recursion in Grammar Results in Conflicts

Throughout a Bison grammar I am using right recursion, and I have read that left recursion is better because it doesn't have to build the whole stack first. However, when I try to switch to left recursion on any of them, I always end up with a lot of conflicts, and I am not seeing why. Can anyone show me a generic example of where usin...

Inspect Bison's $$ variable with GDB

If I set a breakpoint in a Bison .y file, is there a way I can inspect the contents of $$ pseudo variable at that breakpoint? ...

shift/reduce conflicts yacc

see the following code for yacc. if i remove the production factor : '!' expr, the parsing conflict disappears. what is happening here? %{ #include <stdio.h> #include <ctype.h> %} %token TRUE %token FALSE %% line : line expr '\n' { printf("%d\n", $2); } | line '\n' | ; expr : expr "or" term { printf("expr : expr or term\n...

How to find shift/reduce conflict in this yacc file?

When I try to use yacc on the following file I get the error conflicts: 1 shift/reduce How can I find and fix the conflict? /* C-Minus BNF Grammar */ %token ELSE %token IF %token INT %token RETURN %token VOID %token WHILE %token ID %token NUM %token LTE %token GTE %token EQUAL %token NOTEQUAL %% program : declaration_list ; declara...

How to create a symbol table if given a grammar in a yacc file?

I'm given a yacc file and I'm supposed to create a symbol table. What do I do after I use yacc on the file? ...

What's the difference between a parser and a scanner?

I already made a scanner, now I'm supposed to make a parser. What's the difference? ...

How do you make a parser from a yacc file?

I'v been given the following yacc file. How do I make a parser out of it? Do I have to make a scanner first? /* C-Minus BNF Grammar */ %token ELSE %token IF %token INT %token RETURN %token VOID %token WHILE %token ID %token NUM %token LTE %token GTE %token EQUAL %token NOTEQUAL %% program : declaration_list ; declaration_list : d...

What's wrong with this yacc file?

When I run yacc -d parser.y on the following file I get the following errors: parser.y:23.3-24.4: warning: unused value: $4 15 rules never reduced parser.y: warning: 7 useless nonterminals and 15 useless rules parser.y:16.1-14: fatal error: start symbol statement_list does not derive any sentence make: *** [y.tab.c] Error 1 I'm partic...

When is the symbol table for this program built

When I run make on the following Makefile, when is the symbol table built, if it even is? LEX = flex YACC = yacc CC = gcc calcu: y.tab.o lex.yy.o $(CC) -o calcu y.tab.o lex.yy.o -ly -lfl y.tab.c y.tab.h: parser.y $(YACC) -d parser.y y.tab.o: y.tab.c parser.h $(CC) -c y.tab.c lex.yy.o: y.tab.h lex.yy.c $(CC) -c lex.y...

What are the steps I need to do to complete this programming assignment?

I'm having a hard time understanding what I'm supposed to do. The only thing I've figured out is I need to use yacc on the cminus.y file. I'm totally confused about everything after that. Can someone explain this to me differently so that I can understand what I need to do? INTRODUCTION: We will use lex/flex and yacc/Bison to genera...

Bison/Yacc, make literal token return its own value?

Below is my rule, when i replace $2 with '=' my code works. I know by default all literal tokens uses their ascii value (hence why multi character token require a definition) The below doesnt work. The function is called with 0 instead of '=' like i expect. is there an option i can set? (It doesn't appear so via man pages) AssignExpr: ...

Does this program grammar only recognize variables with the name 'ID'?

I need to make a scanner in lex/flex to find tokens and a parser in yacc/bison to process those tokens based on the following grammar. When I was in the middle of making the scanner, it appeared to me that variables, functions, and arrays in this language can only have the name 'ID'. Am I misreading this yacc file? /* C-Minus BNF Gram...

How to tell if something is interpreted literally or not in a yacc file?

Is it true that in the following file, INT is taken literally, while ID is not? How can you tell? /* C-Minus BNF Grammar */ %token ELSE %token IF %token INT %token RETURN %token VOID %token WHILE %token ID %token NUM %token LTE %token GTE %token EQUAL %token NOTEQUAL %% program : declaration_list ; declaration_list : declaration_l...

How does a lexer return a semantic value that the parser uses?

Is it always necessary to do so? What does it look like? ...

How to turn this into a parser

If I just add on to the following yacc file, will it turn into a parser? /* C-Minus BNF Grammar */ %token ELSE %token IF %token INT %token RETURN %token VOID %token WHILE %token ID %token NUM %token LTE %token GTE %token EQUAL %token NOTEQUAL %% program : declaration_list ; declaration_list : declaration_list declaration | declarat...

Why do I get a syntax error in my program made with flex and yacc?

I made a program that is supposed to recognize a simple grammar. When I input what I think is supposed to be a valid statement, I get an error. Specifically, if I type int a; int b; it doesn't work. After I type int a; the program echoes ; for some reason. Then when I type int b; I get syntax error. The lex file: %{ #include <st...