{"id":791,"date":"2022-08-30T15:07:14","date_gmt":"2022-08-30T15:07:14","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/problem-about-lex-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:07:14","modified_gmt":"2022-08-30T15:07:14","slug":"problem-about-lex-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problem-about-lex-collection-of-common-programming-errors\/","title":{"rendered":"problem about lex-Collection of common programming errors"},"content":{"rendered":"<ul>\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\/2a3486169a68e09d34d63f8fe8e7ab80?s=32&amp;d=identicon&amp;r=PG&amp;f=1\" \/><br \/>\nuser2764421<br \/>\npython parsing calculator lex ply<br \/>\nI would like to ask for help for an exercise to do a calculator which recognizes the English words and numbers in Python but now using PLY (Python Lex-Yacc)The numbers and the operators can be given in two forms written as a string using English words, &#8220;plus&#8221; = &#8220;+&#8221;, &#8220;two&#8221; = 2, &#8220;hundred twelve&#8221; = 112, etc&#8230; An example could be these entries: &#8220;twenty five divided by 5&#8221; or &#8220;25 \/ 5&#8221; or &#8220;twenty five divided by five&#8221; the result should be the same, a number 5 (not a string). &#8221; -3 times 4&#8243; will give -12 Division by 0 will give &#8220;Error&#8221; &#8221; 34 divided by 0&#8243; will give &#8220;Error&#8221;This should work for several basic operators &#8220;-&#8220;,&#8221;+&#8221;,&#8221;x&#8221; and &#8220;\/&#8221;<\/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\/19e8985d4750b4f1ac5a0a5dd11ab0f2?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nKavya L<br \/>\nandroid ubuntu android-emulator lex<br \/>\nWhen I run. build\/envsetup.sh lunch full-eng makeI get the following errortarget Executable: tcpdump (out\/target\/product\/generic\/obj\/EXECUTABLES\/tcpdump_intermediates\/LINKED\/tcpdump) p<\/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\/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\/a3c15c47ee93da880a6821a2a2bd1950?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ndstnbrkr<br \/>\ngcc lex lexer<br \/>\nWhen I attempt to compile the output of this trivial lex program:# lex.l integer printf(&#8220;found keyword INT&#8221;);using:<\/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\/39717a9b1fa72fb1f20421109db28f8d?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nbias<br \/>\narrays gcc lex<br \/>\nSo, copying the code from Introduction to Compiler Construction in Unix I wind up with the snippet:\/* samplec.l snipped *\/ static struct rwtable { \/* reserved word table *\/char *rw_name; \/* representation *\/int rw_yylex; \/* yylex() value *\/} rwtable[] = { \/* sorted *\/&#8221;break&#8221;, token(BREAK),&#8221;continue&#8221;, token(CONTINUE),&#8221;else&#8221;, token(ELSE),&#8221;if&#8221;,<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/aed1b37bc11c126adfcfb028d8bd9916?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nlesmana<br \/>\nlinker-error lex flex-lexer<br \/>\nI apologize if this is a straightforward question, but I&#8217;m running into some linker errors with flex when I try compiling the resulting scanner with g++. If I give flex the followi<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/aed1b37bc11c126adfcfb028d8bd9916?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nlesmana<br \/>\nc++ c linux lex flex-lexer<br \/>\nHow can I use a scanner I&#8217;ve written using Flex as part of a program I&#8217;m designing? Specifically, within a c++ class as a method of the class, and from a separate file with just a main method to perform testing.<\/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\/aed1b37bc11c126adfcfb028d8bd9916?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nlesmana<br \/>\nc path windows-xp lex flex-lexer<br \/>\nI&#8217;m trying to use flex and have installed in c:\\gnuwin32\\bin have added such to PATH as well as c:\\dev-cpp\\bin.Calls to gcc work<\/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\/aed1b37bc11c126adfcfb028d8bd9916?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nlesmana<br \/>\nlex flex-lexer<br \/>\nI am writing a lex program. The objective of this problem is that I enter a string Exemple Name@Phon<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/383724e63ab04b146277912c16f27f54?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nNemo<br \/>\nposix lex<br \/>\nSay i have some rules and actions, like so, { do something; } \\. { do_something; } \\(<\/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\/aed1b37bc11c126adfcfb028d8bd9916?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nlesmana<br \/>\ng++ bison lex undefined-reference flex-lexer<br \/>\nI&#8217;m trying to use flex and bison to create a simple scripting language. Right now, I&#8217;m just trying to get a calculator working.I can&#8217;t get it to compile, though. When I run this makefile:OBJECTS = hug.tab.o hug.yy.o PROGRAM = hug.exeCPP = g++ LEX = flex YACC = bison<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/2e07583433759db39a65b2cc2daa8c34?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nPeter Lang<br \/>\nc lex<br \/>\n#include #include #include\/* this is a lexer which recognizes constants , variables ,symbols, identifiers , functions , comments and also header files . It stores the lexemes in 3 different files . One file contains all the headers and the comments . Another file will contain all the variables , another will contain all the symbols. *\/int main() {int i=0,j,k,count=0;char a,b[100],c[10000],d[100];memset ( d, 0, 100 );j=30;FILE *fp1,*fp2;fp1=fopen(&#8220;source.txt&#8221;,&#8221;r&#8221;); \/\/the source file is opened in read only mode which will passed through the lexerfp2=fopen(&#8220;lext.txt&#8221;,&#8221;w&#8221;);\/\/now lets remove all the white spaces and store the rest of the words in a fileif(fp1==NULL){perror(&#8220;failed to open source.txt&#8221;);\/\/return EXIT_FAILURE;}i=0;k=0;while(!feof(fp1)){a=fgetc(fp1);if(a!=&#8217; &#8216;&amp;&amp;a!=&#8217;\\n&#8217;){if (!isalpha(a)){switch(a){case &#8216;+&#8217;:{fprintf(fp2,&#8221;+ &#8212;-&gt; PLUS \\n&#8221;);i=0;break;}case &#8216;-&#8216;:{fprintf(fp2,&#8221;- &#8212;&gt; MINUS \\n&#8221;);i=0;break;}case &#8216;*&#8217;:{fprintf(fp2, &#8220;* &#8212;&gt;MULT \\n&#8221;);i=0;break;}case &#8216;\/&#8217;:{fprintf(fp2, &#8220;\/ &#8212;&gt;DIV \\n&#8221;);i=0;break;}\/\/case &#8216;+=&#8217;:fprintf(fp2, &#8220;%.20s<\/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\/aed1b37bc11c126adfcfb028d8bd9916?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nlesmana<br \/>\nc++ lex flex-lexer flex++<br \/>\nNote: Someone with over 1500 rep.. please add flex++ and bison++ as tags :).Seems like people all over the Internet have been getting the following errors with Flex++:scanner.l:1: bad character: % scanner.l:1: unknown error processing section 1This happens on any example I give Flex++. The version I have is from here and I have t<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/0defa74609a4ce5d51f2467b69c509be?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nOmnifarious<br \/>\nc gcc lex<br \/>\nI am doing the complier project of CS143 of Stanford. It is about implementing a lexical analyzer with the help of flex. Here is the link: https:\/\/github.com\/dunecn\/cs143-pp1I downloaded the source code and wanted to complie the file of scanner.l, it occured<\/li>\n<\/ul>\n<p id=\"rop\"><small>Originally posted 2013-11-09 22:45:43. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Charles Bailey c++ yacc bison lex I 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 [&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-791","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/791","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=791"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/791\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=791"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}