bison

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...

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...

Undefined reference to 'yylex()'

I'm trying to use flex and bison to create a simple scripting language. Right now, I'm just trying to get a calculator working. I can't get it to compile, though. When I run this makefile: OBJECTS = hug.tab.o hug.yy.o PROGRAM = hug.exe CPP = g++ LEX = flex YACC = bison .PHONY: all clean all: $(OBJECTS) $(CPP) $^ -o $(PROGRAM) clean...

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 tokens error. '>>>' and '>>' both assigned number 62

I do something like this in my code CmpExpr: rval '<<' rval { $$ = $1 << $3; } | rval '>>' rval { $$ = $1 >> $3; } | rval '>>>' rval { $$ = (unsigned)($1) >> ($3); } ; the warning i get is tokens '>>>' and '>>' both assigned number 62 How do i make it use different tokens? ...

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: ...

Errors When Using Bison

Now I'm getting other things. When I do a bison -d calc.y I'm getting many source codes in the console (with many m4_define), but it doesn't generate any file. Now my code is like this: %{ #define YYSTYPE double #include <math.h> %} %token NUM %% input: /* empty */ | input line ; line: '\n' | exp '\n' { printf...

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=...

Seeing Garbage When Using Bison

Hello, I'm trying to use Bison to compile(i don't know if this is the correct word to use), but when i try to compile this source code: %{ #define YYSTYPE double #include <math.h> #include <stdio.h> %} %token NUM %% input: /* empty */ | input line ; line: '\n' | exp '\n' { printf ("\t%.10g\n", $1); } ; exp: ...

What Is "\t%.10g\n"

Hello, I'm new at Bison, but in C/C++ no and at this time of development and regular expressions i never heard something like this, only the \n that's used for a new line, but i want to know what is the explanation of \t%.10g, that in the code is like this: line: '\n' | exp '\n' { printf ("\t%.10g\n", $1); } ; Best Rega...

Lexical Tie-Ins with Flex and Bison

Hello all :) I've been looking to recognise a language which does not fit the general Flex/Bison paradigm. It has completely different token rules depending on semantic context. For example: main() { batchblock { echo Hello World! set batchvar=Something echo %batchvar% } } Bison apparently supports recognition of these ty...

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...

Create a Print Function

I'm learning Bison and at this time the only thing that I do was the rpcalc example, but now I want to implement a print function(like printf of C), but I don't know how to do this and I'm planning to have a syntax like this print ("Something here");, but I don't know how to build the print function and I don't know how to create that ; ...

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 ...