problem about yacc-Collection of common programming errors

  • Jonathan Leffler
    grammar bison yacc flex-lexer
    I am writing a compiler for a formatting language and I am writing the bison file. My grammar is correct I think but when I added a recursion rule it and then read the test source file it says that it accepts the rule for the ending tag but that the token is unexpected… The thing is though is that before I added the recursion rule (for some tags inbetween the start and end tag) it worked fine… Here are some detailsThis is the source file\begin{document}\title{test} \author{test} \date{21/02/1985} \pagesetup{35, 80}\end{document}This is the bison file%{#include #include #include extern int yylex();extern int yyparse();extern FILE *yyin;extern FILE *yyout;extern int yylineno;void yyerror(const char*);int header_status(int,int,int,int,int);// counters to check nubmer or document properties used, must all become 1int title = 0;int author = 0;int date = 0;int pgsetup = 0;int tabsz = 0; %}%union{int iVal;char* sVal; }%error-verbose%start source %token SLASH %token BLOCK_S BLOCK_E %token DOC LIST ENUM %token TITLE AUTHOR DATE PG_SETUP TAB_SZ SECTION PARAGRAPH ITEM LINE %token LBRACE RBRACE LPAREN RPAREN %token DOCUMENT DIMENSIONS DATE_VAL STRING %token NUMBER %token ERROR_UN ERROR_IL WORD%%source: /* empty */ | entry_point doc_properties txt_properties exit_point{ if ( header_status(title, author, date, pgsetup, tabsz) == 0 )printf(“\nfail\n”); //YYABORT;};entry_point: SLASH BLOCK_S LBRACE DOC RBRACE ;doc_properties: /* empty */ | doc_properties header_properties;header_properties: title_property { title++; }| author_property { author++; }| date_property { date++; }| pg_setup_property { pgsetup++; }| tab_sz_property { tabsz++; };txt_properties: /* empty */ ;title_property: SLASH TITLE LBRACE STRING RBRACE;author_property: SLASH AUTHOR LBRACE STRING RBRACE;date_property: SLASH DATE LBRACE DATE_VAL RBRACE;pg_setup_property: SLASH PG_SETUP LBRACE DIMENSIONS RBRACE;tab_sz_property: SLASH TAB_SZ LPAREN NUMBER RPAREN;exit_point: SLASH BLOCK_E LBRACE DOC RBRACE;%%int main (int argc, char* argv[]) {if ( argc < 2 || argc > 3){fprintf(stdout, “%s: fatal error: needs one or two arguments\n\n\t%s inputFileName [outputFileName]\n\n”, argv[0], argv[0]);}else if ( argc == 2 ){char* fn = (char *)calloc(strlen(argv[1])+12, sizeof(char));strcpy(fn, argv[1]);strcat(fn, “.output.txt”);fprintf(stderr, “%s: using default output naming: \n\n”, argv[0], fn);yyin = fopen(argv[1], “r”);yyout = fopen(fn, “w”); yyparse();fclose(yyin);fclose(yyout);}else if ( argc == 3 ){yyin = fopen(argv[1], “r”);yyout = fopen(argv[2], “w”); yyparse();fc

  • Charles Bailey
    c++ yacc bison lex
    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 #include “opcodes.h” #include “utils.h”void yyerror(const char *s) {fprintf(stderr, “error: %s\

  • lesmana

  • N mol
    c compiler yacc lex
    I am trying to develop a program which converts infix expression to postfix expression using lex and yacc tools. Here is the source code :(Lex program: ipi.l)ALPHA [A-Z a-z]DIGIT [0-9]%%{ALPHA}({ALPHA}|{DIGIT})* return ID;{DIGIT}+ {yylval=atoi(yytext); return ID;}[\n \t]

  • Bilthon
    compiler android-ndk yacc bison lexical
    UPDATE I know now that parser.h should be generated by the make system from parser.y. The file even has an entry like this:edify_src_files := \lexer.l \parser.y \expr.cBut I still can’t seem to get the executable out of it. (Yes, excecutable, not shared library)I’m trying to compile A

  • Mat
    c linker yacc lex
    hi i recieve the follwing error main.c: undefined reference to yyin main.c: undefined reference to yyparsethis is what i am doing i have a lex file a.l a yacc file b.ymain.c is :#include #include #i

  • user205688
    yacc lex
    how to parse from command line arguements in yacc ?of course i undefined input in both lex & yacc and the

  • alibenmessaoud
    linux ubuntu grammar yacc lex
    I’d like to write down a formal grammar for describing the command line usage of some GNU/Linux tools. First, I would like to define a gra

  • Udi
    yacc lex
    I’m new to yacc/lex and I’m working on a parser that was written by som

  • user2137379
    c string yacc
    i’m working on a school subject about syntax analysis. The goal is to create a small language in order to create vector graphics with the cairo library. We choosed to use an intermediaire state in C.We use Yacc to generate a C code which is compiled by gcc. It works fine but i have some problem with strings.Here is the code is use :int sumChar = 0 ;char outnb1[20];char outnb2[20];sprintf(outnb1, “%f;”, $4);sprintf(outnb2, “%f;”, $8);sumChar = (6+strlen($2)+1+5+strlen($2)+1+strlen(outnb1)+strlen($6)+strlen($7)+strlen(outnb2)+strlen($10)+strlen($11)+1+1+strlen($14)+1);// $ 14 is the string returned by another part of the code.printf(“String = %s\nSIZE = %d\n”,$14,strlen($14));//The printf h

  • master chief
    I want to make a 3 ^ 2 = pow(3, 2) but it’s

  • Mark
    bison yacc context-free-grammar bnf jison
    Let’s say I want to parse my new language that looks like this:main.mylangimport “tags.mylang” cat dog baconAnd there’s another file tags.mylang that looks like this:c

  • ptwiggerl
    gcc bison yacc lex
    Lex and Yacc work, but when I try to compile the file, I’m getting the following error. I have a feeling its a linking issue where compiler can’t find t

  • Sileno Brito
    c reference makefile yacc lex
    I’m trying to use flex and bison to create a simple calc, but i receive errors when i try compile, i don’t experience in YACC or FLEX this is my first program.flex 2.5.35, bison (GNU bison) 2.3, gcc (Debian 4.3.2-1.1) 4.3.2, linux 2.6.26-1-686this is the error:bison -d -y math.yacc -b math lex -P math math.lex gcc lex.math.c -g -Wall -lfl -ll -o In function ‘yyparse’: warning: implicit declaration of function ‘yylex’ /tmp/ccOhwzV0.o: In function `yyparse’: /root/.netbeans/remote/ math/src/model/ undefined reference to `yylex’ collect2: ld returned 1 exit statu

  • Bill the Lizard
    c++ yacc bison lexical-analysis
    I dont get the error, please can you help me out, here is the .l and .y file.thanks.%{ #include “” extern int yylval; %} %% “=” { return EQ; } “!=” { return NE; } “=” { return GE; } “+” { return PLUS; } “-” { return MINUS; } “*” { return MULT; } “/” { return DIVIDE; } “)” { return RPAREN; } “(” { return LPAREN; } “:=” { return ASSIGN; } “;” { return SEMICOLON; } “IF” { return IF; } “THEN” { return THEN; } “ELSE” { return ELSE; } “FI” { return FI; } “WHILE” { return WHILE; } “DO” {

  • Kaz
    xcode yacc
    I am new to Xcode, and I am trying to migrate a c++ application which compile in win32 cygwin using g++ an bison to Xcode. I did search the website for information, before asking questionI have been having issues since the beginning, I narrowed it down to the following. This is my steps:Create a new console application in Xcode This is a C++ application, with no Auto Reference Count A main.cpp file is created Comment out main procedure Create new file, simpleYACC.y Copy the following into the .y file:%{#include //int yylex (void); void yyerror (char const *); %}%token NUM%% exp:; %%int yylex (void) {return 0; }void yyerror (char const *s) {}int main (void) {return yyparse (); }Trying to build it Getting the following error:CompileC /Users/brendanbosman/Library/Developer/Xcode/DerivedData/SimpleYACC-dglitxihrkprgndyxanispqjpbmc/Build/Intermediates/ /Users/brendanbosman/Library/Developer/Xcode/DerivedData/SimpleYACC-dglitxihrkprgndyxanispqjpbmc/Build/Intermediates/

  • Jonathan Leffler
    bison yacc lex flex-lexer
    I’m trying a implement a flex/bison calculator which can do floating point arithmetic. My flex code looks like this%{ #include “” #include void yyerror(char *s); %}digit [0-9] integer {digit}+ real ({digit}+[.]{digit}*)|({digit}*[.]{digit}+) exp ({integer}|{real})[eE]-?{integer}%%({integer}|{real}|{exp}) { yylval = atof(yytext); return NUMBER; } [-+*/\n] { return *yytext; } [ \t\v\f\r]

  • Jonathan Leffler
    yacc nmake newline
    I am compiling a YACC file using Cygwin shell on a PC. I am getting an ‘unknown character \15’. The weird

Originally posted 2013-11-09 21:42:34.