In my yacc file I have things like the following:
var_declaration : type_specifier ID ';'
| type_specifier ID '[' NUM ']' ';' ;
type_specifier : INT | VOID ;
ID, NUM, INT, and VOID are tokens that get returned from flex, so yacc has no problems recognizing them. The problem is that in the above there are things like ...
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 start out with an identifier, I automatically get a syntax error. However, I noticed that using an identifier won't generate an error if it is preceded by 'int'. If a is an...
I'm trying to figure out what legal statements I can make by looking at the grammar in a yacc file, but it's kind of hard. Are there any programs to make this sort of thing easier?
...
I try to input the following into my yacc parser:
int main(void)
{
return;
}
It looks valid to me according to what's defined in the yacc file, but I get a "syntax error" message after the return. Why is that?
The yacc file:
/* C-Minus BNF Grammar */
%{
#include "parser.h"
#include <string.h>
%}
%union
{
int intval;
struct...
One one machine, everything compiles fine. On another machine, it complains about the -ly option when I use gcc to create the output file. If I remove the -ly option, then it makes the program, but then it runs differently. What's happening. How can I get the program to run correctly on this linux machine?
...
I used the -v option in yacc to produce a y.output file. At the top of the file it says
State 98 conflicts: 1 shift/reduce
Further down in the file is the following:
state 98
30 selection_stmt: IF '(' expression ')' statement .
31 | IF '(' expression ')' statement . ELSE statement
ELSE shift, and go to stat...
I work on an open source project focused around Biblical texts. I would like to create a standard string format to build up a search string. I would then need to parse the search string and run the search with the options given. There are a number of different options, from scope of the search, to searching multiple texts, to wildcards, ...
On my machine (Windows running cygwin) it compiles correctly. Flex is version 2.5.35 and bison is version 2.3
On linux machine 1 it compiles correctly. Flex is version 2.5.4 and bison is version 1.875c.
On linux machine 2 it does not compile correctly. Flex is version 2.5.4 and bison is 2.3.
One would expect by looking at the flex/...
I'm getting a message from yacc saying that there is a shift/reduce conflict. I think it's coming from this part of the yacc file.
statement : expression_stmt
| compound_stmt
| selection_stmt
| iteration_stmt
| return_stmt ;
selection_stmt : IF '(' expression ')' statement
| IF '(...
If i forget to put an empty line at the end of any of my files my program gets a syntax error. The problem is my grammar expects a newline to end the current line. Since a newline doesnt exist bison generates a syntax error bc it does not finish the rule.
How do i solve this? I tried making <> return MY_EOF BUT when i do that lex crashe...
I have a grammar like this:
"Match one or more rule1 where rule1 is one or more rule2, where rule2 is one or more rule3, etc. etc. each seperated by newlines". Look at the following example.
start: rule1_list
;
rule1_list: rule1
| rule1_list NEWLINE rule1
;
rule1: rule2
| rule2 NEWLINE rule3...
How to call a flex parser in c ?
...
In my language i can write
a = 1
b = 2
if true { } else { }
if true { } **Here is the problem**
else {}
My grammer doesnt support newlines between statements. An else can only be used with an if. When i add optionalNL in my rule
IfExpr:
IF rval optionalNL codeBlock optionalNL ELSE codeBlock
| IF rval optionalNL codeBlock
The opt...
Lets say I need to run some initialization code everytime I match a rule how can I reduce the redundancy?
rule : TOKEN1 { init(); token1Code(); }
| TOKEN2 { init(); token2Code(); }
;
Also is it possible to do something like
rule : TOKEN1
| TOKEN2
{ codeForToken1OrToken2(); }
;
...
I think my program should be able to recognize the following as a function declaration
int fn(int i) { int n; return; }
but it doesn't.
Here's the relevant part of my yacc file
program : declaration_list ;
declaration_list : declaration_list declaration | declaration ;
declaration : var_declaration
| fun_declaration
...
I am storing the arguments passed to main in yacc in a file. Now I want the lex to read its input from this file rather than the terminal. I know I can point yyin to a file
like yyin = fopen("fn","r"); but this works only when main is in lex. When I use this yyin declaration in main in yacc, it shows an error so please suggest something...
guyz i need to pass an integer array from lex to yacc.i know v can pass an integer using union of yylval but how to pass an array ...pls help me
...
If my yacc parser encounters the following code:
int foo(int a, int b)
should it add int a and int b as attributes of foo? The way I have it now, it enters a and b as separate table entries.
...
I've been using PLY to build up a parser for my language, however I've got a shift/reduce conflict that's causing me some trouble. My language has generic types with a syntax ala C++ templates. So right now I have rules like:
expression : expression LESS expression %prec COMPARISON
expression : template
template : NAME
...
I have been keeping the shift/reduce errors away. Now finally i think i met my match.
Int[] a
a[0] = 1
The problem is int[] is defined as
Type OptSquareBrackets
while a[0] is defined as
Var | Var '[' expr ']'
Var and Type both are defined as VAR which is any valid variable [a-zA-Z][a-zA-Z0-9_]. Apart from adding a dummy token ...