yacc

Allowing variable length lists in yacc

I'd like to be able to parse the following structure: blah { "string-1", "string-2", ..., "string-n" } I'm using flex to tokenize, and that's working perfectly. I'm using yacc (bison) for the parsing. What's the recommended way to allow this structure? Right now, in my test.y file, I've got: blah_command: BLAH OP...

How to build an Array with Bison/Yacc and a Recursive Rule

With Bison, I figured out how to get everything into one long string as follows: arg_list: WORD arg_list { strcat( $1, "IFS" ); $$ = strcat($1, $2); } | WORD ; and: WORD arg_list { printf("%s, %s\n", $1, $2); } But the problem is that I will then have to split up $2 in the second rule again to parse it. Is there a way...

Include struct in the %union def with Bison/Yacc

I am trying to include a struct as part of the union with Bison, but I get an error on the 'struct node args' in %union: parser.y:17: error: field ‘args’ has incomplete type The Code: struct node { char * val; struct node * next; }; %} %union { char * string; struct node args; } %token <string> CD WORD PWD EXIT ...

Error Handing with Flex(lex) and Bison(yacc)

From the Bison Manual: In a simple interactive command parser where each input is one line, it may be sufficient to allow yyparse to return 1 on error and have the caller ignore the rest of the input line when that happens (and then call yyparse again). This is pretty much what I want, but I am having trouble getting to...

How to do Variable Substitution with Flex/Lex and Yacc/Bison

Wikipedia's Interpolation Definition I am just learning flex / bison and I am writing my own shell with it. I am trying to figure out a good way to do variable interpolation. My initial approach to this was to have flex scan for something like ~ for my home directory, or $myVar , and then set what the yyval.stringto what is returned u...

Parser/Lexer ignoring incomplete grammar rules

I have a parser and lexer written in ocamlyacc and ocamllex. If the file to parse ends prematurely, as in I forget a semicolon at the end of a line, the application doesn't raise a syntax error. I realize it's because I'm raising and catching EOF and that is making the lexer ignore the unfinished rule, but how should I be doing this to r...

Confusion about a Bison/YACC Grammar

With the following Grammar, I get a syntax error with this sort of input: ls /home > foo #Runs and works okay, but raises error token ls /home /foo /bar /etc #works okay I think it may have something to do with how lookahead works, but this is my first grammar and I am a bit confused about why it doesn't work this way: external_cmd G...

bison shift/reduce problem moving add op into a subexpr

Originally in the example there was this expr: INTEGER | expr '+' expr { $$ = $1 + $3; } | expr '-' expr { $$ = $1 - $3; } ; I wanted it to be 'more simple' so i wrote this (i realize it would do '+' for both add and subtract. But this is an example) expr: INTEGER | ...

yacc/bison combined word problem

I have an if statement like the below if false { expr } It works, great! but i typed in iffalse { expr } and it works as well :| How do i fix that? the above should be a var name not an if statement -edit- nevermind i figured it out ...

parsing with bison

I bought Flex & Bison from O'Reilly but I'm having some trouble implementing a parser (breaking things down into tokens was no big deal). Suppose I have a huge binary string and what I need to do is add the bits together - every bit is a token: [0-1] { return NUMBER;} 1101010111111 Or for that matter a collection of tokens with no ...

multiple definition of `yyerror'

With Bison (or yacc) how do i solve the error multiple definition of `yyerror' I tried %option noyywrap nodefault yylineno and writing the prototype at the top. No luck. -edit- nevermind. when i copied paste an example to work with i didnt realize i had a yyerror function already. ...

Bison Syntax Error (Beginner)

I'm back and now writing my own language and my OS, but as I'm now starting in the development of my own development language, I'm getting some errors when using Bison and I don't know how to solve them. This is my *.y file code: input: | input line ; line: '\n' | exp '\n' { printf ("\t%.10g\n", $1); } ; exp: ...

bison and lex string vs char

I'm trying to evaluate and expression of the form #SomeFunc[expr][expr]expr expr can be either a string composed from certain characters or a function as above. So this could look something like #SomeFunc[#SomeFunc[#SomeFunc[nm^2][nn]][nm]][n]... The problem is that if I brake into tokens in the form of "#"SomeFunc {yylval.fn=...

Simple Flex/Bison C++

Hello, I already looked for my answer but I didn't get any quick response for a simple example. I want to compile a flex/bison scanner+parser using g++ just because I want to use C++ classes to create AST and similar things. Searching over internet I've found some exploits, all saying that the only needed thing is to declare some funct...

#define in yacc/bisson lex

How would i implement #define's with yacc/bison? I was thinking all define characters much match a regular varaible. Variables are defined as [a-zA-Z_][a-zA-Z0-9_]* so i figure i can put a check there to see if the variable is a define'd worked or not. Then replace the text with what it should be. How can i do that? Right now i want to...

Bison build warning: "-s option given but default rule can be matched"

I get the warning warning, -s option given but default rule can be matched if you google option given but default rule can be matched You'll get results of flex homepage and an entry in a man page. warning, -s option given but default rule can be matched' means that it is possible (perhaps only in a particular start condi...

Multiple flex/bison parsers

Hello, which is the best way to handle multiple flex/bison parsers inside a project? I wrote a parser and now I need a second one in the same project. So far in the third section of parser1.y I inserted the main(..) method and called yyparse from there. What I want to obtain is having two different parsers (parser1.y and parser2.y) and ...

Yacc equivalent for Java

Hello. I'm working on a compiler design project in Java. Lexical analysis is done (using jflex) and I'm wondering which yacc-like tool would be best(most efficient, easiest to use, etc.) for doing syntactical analysis and why. ...

Yacc Grammar Debuggers: Are there any? Are they any good/help?

I've been helping augment a twenty-some year old proprietary language within my company. It is a large, Turing-complete language. Translating it to another grammar regime (such as Antlr) is not an option (I don't get to decide this). For the most part, extending the grammar has gone smoothly. But every once in awhile I'll get a reduce-r...

%union directive in Bison

Hello, I was trying to use an abstract syntax tree in a bison parser, so I tried to use %union directive. Grammar file looks like this: %{ #include "compiler.h" #include "ast.h" #include "common.h" static bool verbose = true; extern "C" { int cyylex(void); void cyyerror(const char *s); } %} %union { ast_node *node; ...