lex

How to run lex file?

拟墨画扇 提交于 2019-12-11 13:26:57
问题 Here is my lex file %% .|\n ECHO; %% How to run this program in windows? How to compile this? Please help me 回答1: Use this procedure to compile: How to compile LEX/YACC files on Windows? Basically: flex olex.l gcc lex.yy.c -o olex.exe And this modified file: %% .|"\n" { ECHO; } %% int yywrap(void) { return 0; } int main(void) { yylex(); return 0; } I hope this works for you. 来源: https://stackoverflow.com/questions/8373821/how-to-run-lex-file

start condition for TeX equations [closed]

你离开我真会死。 提交于 2019-12-11 11:46:14
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . In lex, I can define the following starting condition for equations defined between $...$ . %x EQN1 \$ { BEGIN(EQN1); } <EQN1>{ \$ { BEGIN(INITIAL); } [^\$]* {} } For equations between $$...$$ , how can I define the anything but $$ rule, such as in [^\$]* . I guess [^\$\$]* wouldn't work. 回答1: I think you don't

In LEX, how to parse some code until a special symbol?

▼魔方 西西 提交于 2019-12-11 10:57:16
问题 I was wondering that in LEX, if i want to parse some code until a special symbol. For example: $display("Hello World"); Here, I want to get $display("Hello World") but except ; . I've already tried this: \$"display".*[^;] , it didn't seem to work. Any help will be appreciated. Thanks. 回答1: . matches any character, and the Kleene star * will match many of whatever precedes it. In this case, you're matching display followed by a list of any other character. That'll happen to include the bit you

Matching trailing context in flex

百般思念 提交于 2019-12-11 08:55:17
问题 In the flex manual it mentions a "trailing context" pattern ( r/s ), which means r , but only if followed by s . However the following code doesn't compile (instead it gives an error of "unrecognized rule". Why? LITERAL a/b %% {LITERAL} { } 回答1: The simple answer is that unless you use the -l option, which is not recommended, you cannot put trailing context into a name definition. That's because flex: doesn't allow trailing context inside parentheses; and automatically surrounds expansions of

Lex - yacc program showing syntax error

一个人想着一个人 提交于 2019-12-11 08:48:58
问题 The following two codes have been written in order to perform arithmetic operations on input , but it gives me syntax error all the time Here is the lex program %{ #include "y.tab.h" #include <stdlib.h> %} %% [0-9]+ {yylval = atoi(yytext);return ID;} [*-+/()] {return yytext[0];} '\n' {return END;} . {return yytext[0];} %% Here is the yacc program : %{ #include <stdio.h> #include <stdlib.h> #include "y.tab.h" %} %token ID END %% S: expr END { printf("Answer is : %d\n",$$); exit(1); } expr: ID

Beginner bison flex

一曲冷凌霜 提交于 2019-12-11 07:39:37
问题 How can I print the line number on which an error occurred. I tried using yylineno in the yyerror() function and writing %option yylineno in the .l file but after compiling it gives me an error " yylineno undeclared (first use in this function) " and if I initialize yylineno as 1 it gives me this error: error: redefinition of yylineno lex.yy.c:273: note: previous definition of yylineno was here 回答1: There is a second way to ask flex to provide the global variable yylineno: the command line

Link error when using lex and yacc output in Visual Studio

故事扮演 提交于 2019-12-11 07:33:13
问题 I am using this windows version of flex (lex) and bison (yacc) to port my query compiler from linux to Windows. The output files, lex.yy.c , y.tab.c and y.tab.h are getting generated properly. However, I am getting the following link error. Error 29 error LNK2001: unresolved external symbol _yylval G:\Project\lex.yy.obj QC Error 30 error LNK1120: 1 unresolved externals G:\Project\QC.exe QC I tried copying the above files generated by the original linux versions of flex and yacc to Visual

lex program on counting no of comment lines

旧街凉风 提交于 2019-12-11 07:30:12
问题 here the program counts the no of comment lines, single line comments and multi line comments and gives a total comments output with a file.txt as input file.txt //hellow world /*hello world1*/ /*hello world2 */ /*hello world3 hello world3.1*/ #include<> count.l %{ #include<stdio.h> #include<stdlib.h> int a=0,b=0,c=0,d; %} %% "//".* {a++;} "/*" {b++;} .*"*/" {b--;c++;} %% void main(int argc,char *argv[]){ yyin=fopen(argv[1],"r"); yylex(); printf("single line %d \nmultiline %d \n",a,c); d=a+c;

A parser program for the following grammar

浪子不回头ぞ 提交于 2019-12-11 06:57:17
问题 Write a parser (both Yacc and Lex files) that uses the following productions and actions: S -> cSS {print “x”} S -> a {print “y”} S -> b {print “z”} Indicate the string that it will print when the input is cacba . I am getting this error: when I give input to it, it says valid input and also says syntax error. My Scanner Code is this %{ #include "prac.h" %} %% [c] {return C; } [a] {return A; } [b] {return B; } [ \t] ; \n { return 0; } . { return yytext[0]; } %% int yywrap(void) { return 1; }

ANTLR/Grammar issue: calculator language

旧街凉风 提交于 2019-12-11 05:07:46
问题 I'm attempting to create a boolean expression language/grammar for a personal project. The user will be able to write a string in a Java-like syntax, with provision for variables, which will be evaluated at a later time when the variables have been initialised. Rain For example, a user might enter the string @FOO+7 > 4*(5+@BAR); Later, when the variable FOO is initialised and equal to 6, and BAR is equal to 1, the expression evaluates to 13>24 and thus returns false. I'm using ANTLRworks to