lex

distinguishing a string with flex

Hi, I need to tokenize some strings which will be splitted of according to operators like = and !=. I was successful using regex until the string has != operator. In my case, string was seperated into two parts, which is expected but ! mark is in the left side even it is part of given operator. Therefore, I believe that regex is not sui...

Library to parse ERB files

I am attempting to parse, not evaluate, rails ERB files in a Hpricot/Nokogiri type manner. The files I am attempting to parse contain HTML fragments intermixed with dynamic content generated using ERB (standard rails view files) I am looking for a library that will not only parse the surrounding content, much the way that Hpricot or No...

Unable to compile output of lex

When I attempt to compile the output of this trivial lex program: # lex.l integer printf("found keyword INT"); using: $ gcc lex.yy.c I get: Undefined symbols: "_yywrap", referenced from: _yylex in ccMsRtp7.o _input in ccMsRtp7.o "_main", referenced from: start in crt1.10.6.o ld: symbol(s) not found collect2...

Flex (Lex, not actionscript or w/e) Error

I'm totally new to flex. I'm getting a build error when using flex. That is, I've generated a .c file using flex, and, when running it, am getting this error: 1>lextest.obj : error LNK2001: unresolved external symbol "int __cdecl isatty(int)" (?isatty@@YAHH@Z) 1>C:\...\lextest.exe : fatal error LNK1120: 1 unresolved externals here i...

how to parse from command line arguements in yacc ?

how to parse from command line arguements in yacc ? of course i undefined input in both lex & yacc and then wrote int input(void) { printf("in input\n:"); char c; if(target > limit) return 0; if((c = target[0][offset++]) != '\0') return (c); target++; offset =0; return (' '); } where target contains the command line arguements. But ...

what should the output of a lexer be in c?

#include<stdio.h> int main() { int a,b; a=a+b; printf("%d",a); return 0; } what should be the output if this code is passed through a lexer ...

Flex/bison, error: undeclared

hallo, i have a problem, the followed program gives back an error, error:: Undeclared(first use in function), why this error appears all tokens are declared, but this error comes, can anyone help me, here are the lex and yac files.thanks lex: %{ int yylinenu= 1; int yycolno= 1; %} %x STR DIGIT [0-9] ALPHA ...

error in coding a lexer in c

#include<stdio.h> #include<ctype.h> #include<string.h> /* 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...

Unintentional concatenation in Bison/Yacc grammar.

I am experimenting with lex and yacc and have run into a strange issue, but I think it would be best to show you my code before detailing the issue. This is my lexer: %{ #include <stdlib.h> #include <string.h> #include "y.tab.h" void yyerror(char *); %} %% [a-zA-Z]+ { yylval.strV = yytext; return ID; } [0-9]+ { yylval.intV...

how to call your yacc from a c file ?

i want to parse a command line using a yacc but i want to call it from a c file. how it is possible ? ...

unrecognized rule in lex

I'm writing a program in lex, and it gives me the following error: scanner.l:49: unrecognized rule Line 49 is: {number} {return(NUM);} EDIT: However, the error seems related to the line directly before that, {id} {return(ID);}. It will list the line directly after that rule as the source of the error, even if it's blank. Here's...

strange output in ubuntu terminal when running a lex program

Hi. I'm running a lexical analyzer using lex, and I've got it mostly correct, but my terminal gives strange output once I take out an ECHO statement I was using to help debug the code. With that statement, my output looks like this: max@Max-Ubuntu:~/Desktop/Compiler Project/project2$ ./a.out <../cmmFiles/expression.cmm VOIDID(){ INT...

Indentation control while developing a small python like language

Hello, I'm developing a small python like language using flex, byacc (for lexical and parsing) and C++, but i have a few questions regarding scope control. just as python it uses white spaces (or tabs) for indentation, not only that but i want to implement index breaking like for instance if you type "break 2" inside a while loop that'...

Do lex and yacc provide optimized code?

Do Lex and Yacc provide optimized code or is it required that we write our own code manually for higher performance? ...

Tools to build a UI markup language parser

For a school project, I need to implement a parser for a (probably XML-based) markup language for User Interfaces. Based on the input it generates a HTML document with various UI components (textareas, inputs, panels, dialogs etc.) Do you have any suggestions for tools/libraries I might use for this? (At school we use Flex and Bison, b...

Need Lex and Yacc program which does C syntax-checking

Anybody knows from where I can download a Lex and Yacc program(the source code) for complete syntax checking of a C program? Pls post the link as comment ...

getting started with lex

I need to format some hexdump like this: 00010: 02 03 04 05 00020: 02 03 04 08 00030: 02 03 04 08 00010: 02 03 04 05 00020: 02 03 04 05 02 03 04 05 02 03 04 08 ‍ to 02 03 04 05 02 03 04 08 02 03 04 02 03 04 05 02 03 04 05 02 03 04 05 02 03 04 remove the address fields, if present remove any 08 at the end of a paragraph (followed ...

why return the token name?

%{ #include "y.tab.h" extern int yylval; %} %% [0-9]+ {yylval = atoi (yytext); return NUM;} [ \t] ; \n return 0; . return yytext[0]; %% When I use yylval which is pointing to the value, why should I return the NUM? I mean what does NUM represent (NUM is decalred in YACC section)? Is NUM storing any val...

Building a lexical Analyzer in Java

I am presently learning Lexical Analysis in Compiler Design. In order to learn how really a lexical analyzer works I am trying to build one myself. I am planning to build it in Java. The input to the lexical analyzer is a .tex file which is of the following format. \begin{document} \chapter{Introduction} \section{Scope} ...

How to create a parser which tokenizes a list of words taken from a file?

Hi, I am trying to do a sintax text corrector for my compilers' class. The idea is: I have some rules, which are inherent to the language (in my case, Portuguese), like "A valid phrase is SUBJECT VERB ADJECTIVE", as in "Ruby is great". Ok, so first I have to tokenize the input "Ruby is great". So I have a text file "verbs", with a lot ...