yacc

How to create a parser(lex/yacc)?

喜你入骨 提交于 2019-11-30 05:57:11
I'm having the following file and which need to be parsed --TestFile Start ASDF123 Name "John" Address "#6,US" end ASDF123 The lines start with -- will be treated as comment lines. and the file starts 'Start' and ends with end . The string after Start is the UserID and then the name and address will be inside the double quots. I need to parse the file and write the parsed data into an xml file. So the resulting file will be like <ASDF123> <Name Value="John" /> <Address Value="#6,US" /> </ASDF123> now i'm using pattern matching( Regular Expressions ) to parse the above file . Here is my sample

Simple Flex/Bison C++

拥有回忆 提交于 2019-11-30 05:04:11
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 function prototypes using extern "C" in lex file. So my shady.y file is %{ #include <stdio.h> #include "opcodes.h" #include "utils.h" void yyerror(const char *s) { fprintf(stderr, "error: %s\n", s); } int counter = 0; extern "C" { int yyparse(void); int yylex(void); int

C grammar in GCC source code

℡╲_俬逩灬. 提交于 2019-11-30 03:51:10
I'm looking for the C grammar in GCC source code, more specifically for the grammar in the yacc/bison form. Found the C grammar in Yacc specification in the GCC version 3.3 in the file "c-parse.y" You will not find a C grammar yacc/bison file within the current GCC source code. It was done in the past, before the egcs fork stuff. I cannot give you the exact version and location, but i can tell you that it should be in the 2.x release The current version of GCC has its own C parser GCC of version 4.3 did not contain explicitly written C grammar. Parsing and semantical analysis were performed

how to install Lex and Yacc in Ubuntu? [closed]

最后都变了- 提交于 2019-11-30 00:19:15
I am doing project in SENSE, for that i have to install Lex and Yacc. If you can help me how to install in Ubuntu. I very new to this area. So can you help me. Any website to study the basic of Lex and Yacc halfdan Use the synaptic packet manager in order to install yacc / lex. If you are feeling more comfortable doing this on the console just do: sudo apt-get install bison flex There are some very nice articles on the net on how to get started with those tools. I found the article from CodeProject to be quite good and helpful ( see here ). But you should just try and search for "introduction

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

ⅰ亾dé卋堺 提交于 2019-11-29 21:48:15
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 ; declaration_list : declaration_list declaration | declaration ; declaration : var_declaration | fun_declaration ; var_declaration : type_specifier ID ';' | type_specifier ID '[' NUM ']' ';' ; type_specifier : INT | VOID ; fun_declaration : type_specifier ID '(' params ')'

Generating a compiler from lex and yacc grammar

≡放荡痞女 提交于 2019-11-29 19:47:58
问题 I'm trying to generate a compiler so I can pass him a .c file after. I've downloaded both YACC and LEX grammars from http://www.quut.com/c/ANSI-C-grammar-y.html and named them clexyacc.l and clexyacc.y When generating it on terminal I did : yacc -d clexyacc.y lex clexyacc.l All went fine. When I move on to the last part I get a few errors. The last part is : cc lex.yy.c y.tab.c -oclexyacc.exe But I get these errors : y.tab.c:2261:16: warning: implicit declaration of function 'yylex' is

Resolve conflict in bison grammar with space separated expression lists + if/then/else

狂风中的少年 提交于 2019-11-29 18:07:10
I have the following yacc/bison/happy grammar: %token if TokenIf then TokenThen else TokenElse true TokenTrue false TokenFalse %left APP %right IF %% Hungry : NoHungry | Hungry NoHungry %prec APP | if Hungry then Hungry else Hungry %prec IF NoHungry : true | false bison -v tells me there are two conflicts in the following situation: State 12 2 Hungry: Hungry . NoHungry 3 | if Hungry then Hungry else Hungry . true shift, and go to state 2 false shift, and go to state 3 true [reduce using rule 3 (Hungry)] false [reduce using rule 3 (Hungry)] $default reduce using rule 3 (Hungry) NoHungry go to

Yacc/Bison, minimize amount by grouping math ops

最后都变了- 提交于 2019-11-29 14:42:22
I am looking at the calc source here http://epaperpress.com/lexandyacc/ I see theses lines in calc.y | expr '+' expr { $$ = opr('+', 2, $1, $3); } | expr '-' expr { $$ = opr('-', 2, $1, $3); } | expr '*' expr { $$ = opr('*', 2, $1, $3); } | expr '/' expr { $$ = opr('/', 2, $1, $3); } | expr '<' expr { $$ = opr('<', 2, $1, $3); } | expr '>' expr { $$ = opr('>', 2, $1, $3); } Is there a way to group them? so i can write something like the below instead? | expr mathOp expr { $$ = opr(mathOp, 2, $1, $3); } | expr cmpOp expr { $$ = opr(cmpOp, 2, $1, $3); } NOTE: I am using bison. The problem with

how to parse from a string rather than a file [duplicate]

纵然是瞬间 提交于 2019-11-29 12:59:50
Possible Duplicate: How to make YY_INPUT point to a string rather than stdin in Lex & Yacc (Solaris) i want to parse from a string rather than a file. i know that v can use yy_scan_string fn to do it.but for me it's not working properly so pls help me I fought through this problem myself very recently. The flex documentation on the subject leaves a bit to be desired. I see two things right off the bat that might be tripping you up. First, note that your string needs to be double NULL terminated . That is, you need to take a regular, NULL terminated string and add ANOTHER NULL terminator at the

Bison shift/reduce conflict - tiger compiler

有些话、适合烂在心里 提交于 2019-11-29 11:43:46
I have written a yacc file according to Tiger Book(appendix A, Tiger manual). But there are still some shift/reduce conflicts. I do not know how to resolve these conflicts. % yacc --version bison (GNU Bison) 3.0.2 You can use this cmd to reproduce the problem: % yacc -dvt tiger.y tiger.y: warning: 37 shift/reduce conflicts [-Wconflicts-sr] % cat tiger.y : %{ #include <stdio.h> //#include "util.h" //#include "errormsg.h" int yylex(void); /* function prototype */ void yyerror(char *s) { EM_error(EM_tokPos, "%s", s); } %} %union { int pos; int ival; string sval; } %token <sval> ID STRING %token