Questions tagged [lex]

Lex is a computer program that generates lexical analyzers ("scanners" or "lexers"). Lex is commonly used with the yacc parser generator. For questions about Amazon Lex, use the tag amazon-lex instead.

Lex is a computer program that generates lexical analyzers ("scanners" or "lexers"). Lex is commonly used with the parser generator.

References:

See also:

Not to be confused with .

1809 questions
5
votes
1 answer

Difference Between '?' and '*' in regular expressions

I am learning regular expressions to use them in lex program. I've Seen here that, in Regular Expressions: '*' matches 0 or more occurances of pattern '?' matches 0 or 1 occurance of the pattern By this I'm kinda Confused. I mean: if we can…
Vedant Terkar
  • 4,553
  • 8
  • 36
  • 62
5
votes
1 answer

Flex/bison syntax error

I am trying to write a grammar which will be able to consume the following input: begin #this is a example x = 56; while x > 0 do begin point 15.6 78.96; end; end; Here is the lexer.l file: %option noyywrap %{ #include…
Vardan Hovhannisyan
  • 1,101
  • 3
  • 17
  • 40
5
votes
1 answer

flex/lex yacc/bison multithreaded environment

Can I use the code generated by flex/bison|lex/yacc in a multithreaded environment ? I'm afraid there are a lot of global variables. How can it be fixed ?
Pierre
  • 34,472
  • 31
  • 113
  • 192
5
votes
1 answer

How to make lex/flex recognize tokens not separated by whitespace?

I'm taking a course in compiler construction, and my current assignment is to write the lexer for the language we're implementing. I can't figure out how to satisfy the requirement that the lexer must recognize concatenated tokens. That is, tokens…
millimoose
  • 39,073
  • 9
  • 82
  • 134
5
votes
2 answers

Matching trailing context in flex

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} { }
jleahy
  • 16,149
  • 6
  • 47
  • 66
5
votes
1 answer

lex: default rule for unrecognized strings

In ocamllex, I can use _ as a lexer rule to match any string that does not match previously defined rules, and raise errors. How can achieve this in lex/flex?
osolmaz
  • 1,873
  • 2
  • 24
  • 41
5
votes
1 answer

Using character literals as terminals in bison

I'm trying to understand flex/bison, but the documentation is a bit difficult for me, and I've probably grossly misunderstood something. Here's a test case: http://namakajiri.net/misc/bison_charlit_test/ File "a" contains the single character 'a'. …
melissa_boiko
  • 153
  • 10
5
votes
3 answers

Removing nested comments bz lex

How should I do program in lex (or flex) for removing nested comments from text and print just the text which is not in comments? I should probably somehow recognize states when I am in comment and number of starting "tags" of block comment. Lets…
user1097772
  • 3,499
  • 15
  • 59
  • 95
5
votes
1 answer

Lex/Yacc grammar files for LOGO (or Turtle) programming language

I'm wondering if there already exists files that describe the Lex and Yacc tokens and parsing rules for LOGO. I'll be using PLY for Python to parse the LOGO commands. I have to convert the files to Python so I'm hoping to use the files more as a…
Reactgular
  • 52,335
  • 19
  • 158
  • 208
5
votes
2 answers

Define and in a lexer

I am trying to implement a front end which attempts to conform to a subset of this specification. It seems that many things are clearly defined in the reference, except and , which are nevertheless often used. Here is a…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
5
votes
1 answer

Flex/Bison: Bad token management?

I've a problem in my lexer and in my parser. First, in my lexer I've a line like that: "if" beginScope(stOTHER); return IF; And in my parser: stmt: IF '(' exp ')' stmts ... stmts: stmt | '{' stmt_list '}' | '{' '}' In a code like…
Unarelith
  • 495
  • 3
  • 13
4
votes
2 answers

How to discard non-terminal in grammar file with PLY (Python Lex-Yacc)

I have faced a problem when using PLY. I want to create a call graph generator by PLY. In some situation, I need to discard some tokens in the grammar file. That is because I need to do something when the parser recognize that token before I discard…
wani
  • 177
  • 2
  • 7
4
votes
1 answer

LEX & YACC - spaces in expressions

I am reading in a file and for some reason i get a syntax error when i try an expression like 5+5 however, if i do this 5 + 5 it works good. I am baffled why it would do this? Here is my lex file( i will leave out main that reads in a file): %{ …
user249375
4
votes
1 answer

Tracking source position of AST nodes in a compiler (ocaml)

I'm writing a compiler in ocaml, using ocamllex/yacc. Things are going well, but I've a design problem. For each AST node I create, it'd be good to have information about line/character position of that node in the source code. That would be useful…
pbp
  • 1,461
  • 17
  • 28
4
votes
1 answer

Build compiler Object Oriented

I'm currently working on a project for my class. I'm building a compiler with Flex (lex) and Bison (YACC) and C. I have done just a little bit of semantic an syntax analysis but i have been thinking how im going to implement the object oriented…
Ccortina
  • 587
  • 14
  • 31