yacc

String input to flex lexer

I want to create a read-eval-print loop using flex/bison parser. Trouble is, the flex generated lexer wants input of type FILE* and i would like it to be char*. Is there anyway to do this? One suggestion has been to create a pipe, feed it the string and open the file descriptor and send to the lexer. This is fairly simple but it feels ...

Most effective way to parse C-like definition strings?

Hello all. I've got a set of function definitions written in a C-like language with some additional keywords that can be put before some arguments(the same way as "unsigned" or "register", for example) and I need to analyze these lines as well as some function stubs and generate actual C code from them. Is that correct that Flex/Yacc ...

Haskell parsing tools - yacc:lex :: happy:?

So, it seems like Happy is a robust replacement for yacc in Haskell. Is there an equally robust lexer generator to replace lex/flex? ...

Best modern text parsing? AKA When to use Lex and Yacc?

I have as input blocks of text with commands and arguments, one per line, such as XYZ ARG1,ARG2,ARG3,...,ARGN And I want to verify that the arguments to XYZ are well formed for that particular command and execute the correct block of code if they are. There are something like ~100 commands, some of which have variable numbers of argum...

Tokenizing left over data with lex/yacc

Forgive me, I'm completely new to parsing and lex/yacc, and I'm probably in way over my head, but nonetheless: I'm writing a pretty basic calculator with PLY, but it's input might not always be an equation, and I need to determine if it is or not when parsing. The extremes of the input would be something that evaluates perfectly to an e...

How to fix YACC shift/reduce conflicts from post-increment operator?

I'm writing a grammar in YACC (actually Bison), and I'm having a shift/reduce problem. It results from including the postfix increment and decrement operators. Here is a trimmed down version of the grammar: %token NUMBER ID INC DEC %left '+' '-' %left '*' '/' %right PREINC %left POSTINC %% expr: NUMBER | ID | ...

Regex for lex

I am developing a simple translator from MathML to Latex, using Lex and Yacc. In my lex file containing the regex rules I have one defined for arithmetic operators [-+*=/]. I want to extended so that it would recognize plus-minus (+-) and invisible times ('&InvisibleTimes'), but I'm unfamiliar with regex and I need some help. ...

YACC compile error

I am compiling a YACC file using Cygwin shell on a PC. I am getting an 'unknown character \15'. The weird thing is that a co-worker on another machine can compile the exact same file using the same shell with no warnings or errors. Is there some kind of flag I need to set in my shell or with the compiler? We are using nmake and a Vis...

How do I implement forward references in a compiler?

I'm creating a compiler with Lex and YACC (actually GNU Flex and Bison). The language allows unlimited forward references to any symbol (like C#). The problem is that it's impossible to parse the language without knowing what an identifier is. The only solution I know of is to lex the entire source, and then do a "breadth-first" parse, ...

Help with Shift/Reduce conflict - Trying to model (X A)* (X B)*

Im trying to model the EBNF expression ("declare" "namespace" ";")* ("declare" "variable" ";")* I have built up the yacc (Im using MPPG) grammar, which seems to represent this, but it fails to match my test expression. The test case i'm trying to match is declare variable; The Token stream from the lexer is KW_Declare KW_Varia...

Making YACC output an AST (token tree)

Is it possible to make YACC (or I'm my case MPPG) output an Abstract Syntax Tree (AST). All the stuff I'm reading suggests its simple to make YACC do this, but I'm struggling to see how you know when to move up a node in the tree as your building it. ...

what is the difference between lex and yacc

i have worked with lex for excuting some code whenever some regular expression is found, Can yacc do something more than that?if yes what ...

Parsing PHP/JavaScript document structure in Delphi

Hi, I need to parse PHP & JavaScript documents structure to get the info about document functions & their parameters, classes & their methods, variables, and so on ... I'm wondering if there is any solution for doing that (no regular expressions) ... I've heard about something called "lexing" however I was unable to find any examples eve...

How to get entire input string in Lex and Yacc?

OK, so here is the deal. In my language I have some commands, say XYZ 3 5 GGB 8 9 HDH 8783 33 And in my Lex file XYZ { return XYZ; } GGB { return GGB; } HDH { return HDH; } [0-9]+ { yylval.ival = atoi(yytext); return NUMBER; } \n { return EOL; } In my yacc file start : commands ; commands : command | command EOL co...

Good parser generator (think lex/yacc or antlr) for .NET? Build time only?

Is there a good parser generator (think lex/yacc or antlr) for .NET? Any that have a license that would not scare lawyers? Lot’s of LGPL but I am working on embedded components and some organizations are not comfortable with me taking an LGPL dependency. I've heard that Oslo may provide this functionality but I'm not sure if it's a bui...

How to initialize Bison's %union value?

In Bison I have a union %union { std::string* sval; } And I want to use it like this In Lex: *(yylval->sval) = "ABCD"; Rather than yylval->sval = new std::string("ABCD"); To prevent memory leaks easily However I need some way to allocated a std::string to sval to begin with. How can I do that? ...

Implementing a XML translator using XML's EBNF

I'm contemplating the idea of implementing a XML translator using a compiler generator, based on the W3C's XML 1.1 spec, which includes a complete EBNF grammar. More precisely, I plan to use Qi-YACC because I want to learn this tool. It will be my first foray into using any compiler-compiler. The first kind of translation I'm planning ...

Creating a foreach keyword with yacc or Bison and Flex

I have developed a interpreted programming language. It is strongly based on C. The problem is, I want to add a foreach directive and have no clue how to. I am using Bison and Flex as the parser and lexer generator. ...

Yacc/Jay grammar file for Javascript?

I'm trying to find a grammar file for Javascript for Yacc (preferably for Jay, but since Jay is a Yacc clone I should be fine, since I need to implement it on .NET). ...

Yacc/Bison, minimize amount by grouping math ops

I am looking at the calc source here http://epaperpress.com/lexandyacc/ I see theses lines in calc.y | expr '+' expr { $$ = opr('+', 2, $1, $3); } | expr '-' expr { $$ = opr('-', 2, $1, $3); } | expr '*' expr { $$ = opr('*', 2, $1, $3); } | expr '/' expr { $$ = opr('/', 2, $1, $3); } | expr '<' expr ...