lex

Regular expression for a string literal in flex/lex

I'm experimenting to learn flex and would like to match string literals. My code currently looks like: "\""([^\n\"\\]*(\\[.\n])*)*"\"" {/*matches string-literal*/;} I've been struggling with variations for an hour or so and can't get it working the way it should. I'm essentially hoping to match a string literal that can't conta...

how to create a gui for my compiler ?

i am using flex as lexical analyzer and bison as parser generator , but the result of both is console window and i want to have a gui (like ide) for it so how to do that . thanks ...

Where's the syntax error in this (f)lex snippet?

I'm having a great time doing a lexer using flex. Problem is, my code editor doesn't color the syntax of the file, and it seems my rule has an error in it. Since I'm not too sure about how to use single quotes and double quotes inside intervals, I thought I'd share that snippet with you: [^\\\'\n]+ { wchar_t* string; utf8_decode...

Lex and Yacc in PHP

Is there an implementation of Lex and Yacc in PHP? If not, can anyone suggest a lexical analyser and parser generator (ie, anything like Lex and Yacc) that will create PHP code. I'm not too worried about the performance of the resulting parser. I am sick of using regex to parse things that really shouldn't be parsed with regex... ...

where to find a real example on flex and bison ?

i need a n example on flex and bison , so i can learn how to build ast tree and symbol table and do semantic analysis ...

Is there a good Emacs mode or method for lex/flex/yacc/bison files?

Editing lex or yacc files with Emacs is a nuisance: if I use C mode the indenting goes wrong, and if I don't use C mode I can't use indenting. Does anyone have a trick, a method, or an editing mode to get around it? ...

Is there a better (more modern) tool than lex/flex for generating a tokenizer for C++?

I recent added source file parsing to an existing tool that generated output files from complex command line arguments. The command line arguments got to be so complex that we started allowing them to be supplied as a file that was parsed as if it was a very large command line, but the syntax was still awkward. So I added the ability...

Is there rule of thumb for catching errors in Lex/Yacc parsing?

Should we catch errors while parsing general purpose language as early as possible (in Lex) or where it is more convenient and give us more information (in Yacc)? How various languages solve this problem? ...

Unable to recognize single line comments in Lex

Am learning lex in this process, I'm generating tokens for the C language, and am trying to recognize single line comments "//", but am having a conflict with the division operator [1-9][0-9]*|0x[0-9a-fA-F][0-9a-fA-F]* return NUMBER; [a-zA-Z][a-zA-Z0-9]* return IDENT; / ...

What is the difference between lex/yacc and fslex/fsyacc?

I'm learning F# because I'd like to write a lexer and parser. I have a tiny bit of experience with this sort of processing but really need to learn it properly as well as F#. When learning the lexing/parsing functionality of F#, is studying lex and yacc sufficient? Or are there some differences that means code for lex/yacc will not wor...

lex (flex) generated program not parsing whole input

I have a relatively simple lex/flex file and have been running it with flex's debug flag to make sure it's tokenizing properly. Unfortunately, I'm always running into one of two problems - either the program the flex generates stops just gives up silently after a couple of tokens, or the rule I'm using to recognize characters and strings...

Problems with data types in flex

Hi everybody!!! I have a problem. I'm writing a program with flex and I'm using this code: %union { int entero; char *cadena; TipoDato tipo; } This code is for my data types. I want evaluate the next line: expresion SUM expresion where SUM is the operation sum for evaluate, for example 69 + 60 When I write this if...

Getting types for multiple members

Hi all. I'm writing a program with Yacc/Flex and I'm using the following code (not exactly the same because I'm mixing code from other file): DataType datat; %union { int integer; char *string; DataType type; } Integer { yylval.type = INTEGER; return INT; } %type <type> INT data : INTNUM { yylval.type = INTEGER; } ...

How can I implement #include constructs with Flex and YACC?

During parsing, if I encounter a include token I want to instruct YACC to open the file specified as input and to begin parsing this. Once this parsing is finished, I want to instruct YACC to return to the file and continue parsing directly after the include expression. I will restrict the include depth level to one. ...

Lex: How do I Prevent it from matching against substrings?

For example, I'm supposed to convert "int" to "INT". But if there's the word "integer", I don't think it's supposed to turn into "INTeger". If I define "int" printf("INT"); the substrings are matched though. Is there a way to prevent this from happening? ...

Sharing memory among YACC, Lex, and C files

I have a YACC (Bison) grammar, a Lex (Flex) tokenizer, and a C program among which I need to share a struct (or really any variable). Currently, I declare the actual object in the grammar file and extern it wherever I need it (which is to say, my C source file), usually using a pointer to manipulate it. I have a shared header (and implem...

Looking for a Java grammar in lex/yacc format

Does anyone know an online repository for lex/yacc format grammars? I'm looking for a Java grammar to make a quicky sourcecode converter. Thank you! edit: I'm preferably looking for lex/yacc because I want to use fslex/fsyacc with as little grammar rewriting as possible. ...

How do I generate different yyparse functions from lex/yacc for use in the same program?

Hi, I want to generate two separate parsing functions from lex/yacc. Normally yacc gives you a function yyparse() that you can call when you need to do some parsing, but I need to have several different yyparses each associated with different lexers and grammars. The man page seems to suggest the -p (prefix) flag, but this didn't work f...

Yacc and Lex inclusion confusion

I am wondering how to correctly compile a program with a Makefile that has calls to yyparse in it? This is what I do: I have a Makefile that compiles all my regular files and they have no connections to y.tab.c or lex.yy.c (Am I supposed to have them?) I do this on top of my code: #include "y.tab.c" #include "lex.yy.c" #include "y.ta...

Big problem with regular expression in Lex (lexical analyzer)

Hi, I have some content like this: author = "Marjan Mernik and Viljem Zumer", title = "Implementation of multiple attribute grammar inheritance in the tool LISA", year = 1999 author = "Manfred Broy and Martin Wirsing", title = "Generalized Heterogeneous Algebras and Partial Interpretation...