lex

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...

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? ...

Handling error conditions in Lex rather than Yacc?

Suppose I have a lex regular expression like [aA][0-9]{2,2}[pP][sS][nN]? { return TOKEN; } If a user enters A75PsN A75PS It will match But if a user says something like A75PKN I would like it to error and say "Character K not recognized, expecting S" What I am doing right now is just writing it like let [a-zA-Z] num [0-9] {l...

What does the "yy" in lex.yy.c stand for?

What does the "yy" in lex.yy.c stand for? ...

Error Handing with Flex(lex) and Bison(yacc)

From the Bison Manual: In a simple interactive command parser where each input is one line, it may be sufficient to allow yyparse to return 1 on error and have the caller ignore the rest of the input line when that happens (and then call yyparse again). This is pretty much what I want, but I am having trouble getting to...

How to do Variable Substitution with Flex/Lex and Yacc/Bison

Wikipedia's Interpolation Definition I am just learning flex / bison and I am writing my own shell with it. I am trying to figure out a good way to do variable interpolation. My initial approach to this was to have flex scan for something like ~ for my home directory, or $myVar , and then set what the yyval.stringto what is returned u...

Undefined reference to 'yylex()'

I'm trying to use flex and bison to create a simple scripting language. Right now, I'm just trying to get a calculator working. I can't get it to compile, though. When I run this makefile: OBJECTS = hug.tab.o hug.yy.o PROGRAM = hug.exe CPP = g++ LEX = flex YACC = bison .PHONY: all clean all: $(OBJECTS) $(CPP) $^ -o $(PROGRAM) clean...

yacc/bison combined word problem

I have an if statement like the below if false { expr } It works, great! but i typed in iffalse { expr } and it works as well :| How do i fix that? the above should be a var name not an if statement -edit- nevermind i figured it out ...

multiple definition of `yyerror'

With Bison (or yacc) how do i solve the error multiple definition of `yyerror' I tried %option noyywrap nodefault yylineno and writing the prototype at the top. No luck. -edit- nevermind. when i copied paste an example to work with i didnt realize i had a yyerror function already. ...

How to declare C array of strings

I'm working on a simple lex program for class, and in it I'm creating a very rudimentary symbol table, just an array of strings with a linear scan for search. I've declared it as: char* identifiers[100]; And I'm using it like so: found = false; for (i = 0; i < seen_identifiers; i++) { if (!strcmp(identifiers[i], yytext)) { ...

bison and lex string vs char

I'm trying to evaluate and expression of the form #SomeFunc[expr][expr]expr expr can be either a string composed from certain characters or a function as above. So this could look something like #SomeFunc[#SomeFunc[#SomeFunc[nm^2][nn]][nm]][n]... The problem is that if I brake into tokens in the form of "#"SomeFunc {yylval.fn=...

Seeing Garbage When Using Bison

Hello, I'm trying to use Bison to compile(i don't know if this is the correct word to use), but when i try to compile this source code: %{ #define YYSTYPE double #include <math.h> #include <stdio.h> %} %token NUM %% input: /* empty */ | input line ; line: '\n' | exp '\n' { printf ("\t%.10g\n", $1); } ; exp: ...

Quotes in string (f)lex AT&T

How can I write a regular definition in (f)lex for quoted strings from AT&T language? Example of string that come to my mind: "abc" "a\"bc" "abc\" "abc\"" Later edit: "abc" "def" should be matched as two strings "ab\"c" "def" should be matched as two strings "abc\" "def" should be matched as two strings The definition \"[^\"]\" ...

Lexical Tie-Ins with Flex and Bison

Hello all :) I've been looking to recognise a language which does not fit the general Flex/Bison paradigm. It has completely different token rules depending on semantic context. For example: main() { batchblock { echo Hello World! set batchvar=Something echo %batchvar% } } Bison apparently supports recognition of these ty...

Simple Flex/Bison C++

Hello, I already looked for my answer but I didn'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've found some exploits, all saying that the only needed thing is to declare some funct...

#define in yacc/bisson lex

How would i implement #define's with yacc/bison? I was thinking all define characters much match a regular varaible. Variables are defined as [a-zA-Z_][a-zA-Z0-9_]* so i figure i can put a check there to see if the variable is a define'd worked or not. Then replace the text with what it should be. How can i do that? Right now i want to...

Bison build warning: "-s option given but default rule can be matched"

I get the warning warning, -s option given but default rule can be matched if you google option given but default rule can be matched You'll get results of flex homepage and an entry in a man page. warning, -s option given but default rule can be matched' means that it is possible (perhaps only in a particular start condi...

Multiple flex/bison parsers

Hello, which is the best way to handle multiple flex/bison parsers inside a project? I wrote a parser and now I need a second one in the same project. So far in the third section of parser1.y I inserted the main(..) method and called yyparse from there. What I want to obtain is having two different parsers (parser1.y and parser2.y) and ...

%union directive in Bison

Hello, I was trying to use an abstract syntax tree in a bison parser, so I tried to use %union directive. Grammar file looks like this: %{ #include "compiler.h" #include "ast.h" #include "common.h" static bool verbose = true; extern "C" { int cyylex(void); void cyyerror(const char *s); } %} %union { ast_node *node; ...