{"id":709,"date":"2022-08-30T15:05:52","date_gmt":"2022-08-30T15:05:52","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/problem-about-yacc-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:05:52","modified_gmt":"2022-08-30T15:05:52","slug":"problem-about-yacc-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problem-about-yacc-collection-of-common-programming-errors\/","title":{"rendered":"problem about yacc-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/7d0d66b076e3bc70819e50f8a25af8df?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJonathan Leffler<br \/>\ngrammar bison yacc flex-lexer<br \/>\nI 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&#8230; The thing is though is that before I added the recursion rule (for some tags inbetween the start and end tag) it worked fine&#8230; 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(&#8220;\\nfail\\n&#8221;); \/\/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 &lt; 2 || argc &gt; 3){fprintf(stdout, &#8220;%s: fatal error: needs one or two arguments\\n\\n\\t%s inputFileName [outputFileName]\\n\\n&#8221;, argv[0], argv[0]);}else if ( argc == 2 ){char* fn = (char *)calloc(strlen(argv[1])+12, sizeof(char));strcpy(fn, argv[1]);strcat(fn, &#8220;.output.txt&#8221;);fprintf(stderr, &#8220;%s: using default output naming: \\n\\n&#8221;, argv[0], fn);yyin = fopen(argv[1], &#8220;r&#8221;);yyout = fopen(fn, &#8220;w&#8221;); yyparse();fclose(yyin);fclose(yyout);}else if ( argc == 3 ){yyin = fopen(argv[1], &#8220;r&#8221;);yyout = fopen(argv[2], &#8220;w&#8221;); yyparse();fc<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/a8db27c91db97757a829c7971fd62b84?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nCharles Bailey<br \/>\nc++ yacc bison lex<br \/>\nI already looked for my answer but I didn&#8217;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&#8217;ve found some exploits, all saying that the only needed thing is to declare some function prototypes using extern &#8220;C&#8221; in lex file.So my shady.y file is%{ #include #include &#8220;opcodes.h&#8221; #include &#8220;utils.h&#8221;void yyerror(const char *s) {fprintf(stderr, &#8220;error: %s\\<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/aed1b37bc11c126adfcfb028d8bd9916?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nlesmana<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/9f4d41e345d742a2a060a70c9d01a2b8?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nN mol<br \/>\nc compiler yacc lex<br \/>\nI 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]<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/3c12af4faf6b6ca035a8333b3adf4173?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nBilthon<br \/>\ncompiler android-ndk yacc bison lexical<br \/>\nUPDATE I know now that parser.h should be generated by the make system from parser.y. The Android.mk file even has an entry like this:edify_src_files := \\lexer.l \\parser.y \\expr.cBut I still can&#8217;t seem to get the executable out of it. (Yes, excecutable, not shared library)I&#8217;m trying to compile A<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/815ee86e14bbedd4f353cad0680c7be5?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMat<br \/>\nc linker yacc lex<br \/>\nhi 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<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/2bb18dd9d45709c3f7bcd27b415519c5?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nuser205688<br \/>\nyacc lex<br \/>\nhow to parse from command line arguements in yacc ?of course i undefined input in both lex &amp; yacc and the<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/1e3155658f692981ca8d75904a8c0918?s=128&amp;d=identicon&amp;r=PG\" \/><br \/>\nalibenmessaoud<br \/>\nlinux ubuntu grammar yacc lex<br \/>\nI&#8217;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<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/920d3f95a8dfb28d2e716ce91f40105a?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nUdi<br \/>\nyacc lex<br \/>\nI&#8217;m new to yacc\/lex and I&#8217;m working on a parser that was written by som<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/9091d5d24cc99bd26c3ee11bc5041bb3?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nuser2137379<br \/>\nc string yacc<br \/>\ni&#8217;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, &#8220;%f;&#8221;, $4);sprintf(outnb2, &#8220;%f;&#8221;, $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(&#8220;String = %s\\nSIZE = %d\\n&#8221;,$14,strlen($14));\/\/The printf h<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/b537a8a32f248a6ee92c9bc4a262ecfc?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nmaster chief<br \/>\nyacc<br \/>\nI want to make a 3 ^ 2 = pow(3, 2) but it&#8217;s<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/eec2e174897771bff4bf95039074b57e?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMark<br \/>\nbison yacc context-free-grammar bnf jison<br \/>\nLet&#8217;s say I want to parse my new language that looks like this:main.mylangimport &#8220;tags.mylang&#8221; cat dog baconAnd there&#8217;s another file tags.mylang that looks like this:c<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/34a24e2f66b9cba0ee3c6ca984026486?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nptwiggerl<br \/>\ngcc bison yacc lex<br \/>\nLex and Yacc work, but when I try to compile the y.tab.c file, I&#8217;m getting the following error. I have a feeling its a linking issue where compiler can&#8217;t find t<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/e7d9b73fd49dee3c84cc0aeb7b748c17?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nSileno Brito<br \/>\nc reference makefile yacc lex<br \/>\nI&#8217;m trying to use flex and bison to create a simple calc, but i receive errors when i try compile, i don&#8217;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 math.tab.c -g -Wall -lfl -ll -o math.parse.so math.tab.c: In function \u2018yyparse\u2019: math.tab.c:1244: warning: implicit declaration of function \u2018yylex\u2019 \/tmp\/ccOhwzV0.o: In function `yyparse&#8217;: \/root\/.netbeans\/remote\/192.168.56.101\/silenobrito-nb-Windows-x86_64\/D\/source\/lib- math\/src\/model\/math.tab.c:1244: undefined reference to `yylex&#8217; collect2: ld returned 1 exit statu<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/fc763c6ff6c160ddad05741e87e517b6?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nBill the Lizard<br \/>\nc++ yacc bison lexical-analysis<br \/>\nI dont get the error, please can you help me out, here is the .l and .y file.thanks.%{ #include &#8220;ifanw.tab.h&#8221; extern int yylval; %} %% &#8220;=&#8221; { return EQ; } &#8220;!=&#8221; { return NE; } &#8220;=&#8221; { return GE; } &#8220;+&#8221; { return PLUS; } &#8220;-&#8221; { return MINUS; } &#8220;*&#8221; { return MULT; } &#8220;\/&#8221; { return DIVIDE; } &#8220;)&#8221; { return RPAREN; } &#8220;(&#8221; { return LPAREN; } &#8220;:=&#8221; { return ASSIGN; } &#8220;;&#8221; { return SEMICOLON; } &#8220;IF&#8221; { return IF; } &#8220;THEN&#8221; { return THEN; } &#8220;ELSE&#8221; { return ELSE; } &#8220;FI&#8221; { return FI; } &#8220;WHILE&#8221; { return WHILE; } &#8220;DO&#8221; {<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/633e1f643d2c9b043231b4a32b078907?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nKaz<br \/>\nxcode yacc<br \/>\nI 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\/SimpleYACC.build\/Debug\/SimpleYACC.build\/Objects-normal\/x86_64\/Simple.tab.o \/Users\/brendanbosman\/Library\/Developer\/Xcode\/DerivedData\/SimpleYACC-dglitxihrkprgndyxanispqjpbmc\/Build\/Intermediates\/SimpleYACC.build\/Debug\/SimpleYACC.build<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/7d0d66b076e3bc70819e50f8a25af8df?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJonathan Leffler<br \/>\nbison yacc lex flex-lexer<br \/>\nI&#8217;m trying a implement a flex\/bison calculator which can do floating point arithmetic. My flex code looks like this%{ #include &#8220;calc.tab.h&#8221; #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]<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/7d0d66b076e3bc70819e50f8a25af8df?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJonathan Leffler<br \/>\nyacc nmake newline<br \/>\nI am compiling a YACC file using Cygwin shell on a PC. I am getting an &#8216;unknown character \\15&#8217;. The weird<\/li>\n<\/ul>\n<p id=\"rop\"><small>Originally posted 2013-11-09 21:42:34. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-709","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/709","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=709"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/709\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=709"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=709"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=709"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}