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.
1,834
questions
1
vote
0
answers
35
views
I'm trying to build a nand2tetris assembler but the ply.lex library in python keep breaking my assembly instructions to different lines
the first thought I had was that I didn't manage to handle the new line character properly because it keeps throwing the new line character "\n" whenever I try to append the instructions for ...
0
votes
0
answers
55
views
When writing my own lex/yacc, my code that was cpmpiled by g++ producted a weird bug
Could you please help me identify where the issue might be in my code, or is there possibly a problem with the compiler itself?"
I was writing my own lex/yacc by cpp. There is some codes for ...
0
votes
1
answer
80
views
ignoring characters in lex/flex input or: understanding YY_INPUT
I'm parsing files with words that need to be spell checked. The input is in RTF-format.
The words to be checked have \- strings in them designating the predetermined breaking point where a word should ...
1
vote
1
answer
46
views
How to write a Flex code for matches protocol (http, https), domain name and optional port number, and path of the URL
How to write a Flex code for matches protocol (http, https), domain name and optional port number, and path of the URL
sample input:
http://google.com
https://google.com:6060
https://google.com:6060/...
0
votes
0
answers
16
views
Single variable equations using yacc and lex
I am making a chat using lex and yacc. Now the chat can answer different questions and make simple calculus using +, -, * and / . I want to add a functionality that permits the chat to do some simple ...
1
vote
0
answers
32
views
Unknown type name ‘Node’ in the parser file. (Yacc program)
I've been working on a Yacc program (parser.y) to develop a small compiler that handles arithmetic operations. I'm using Yacc (Bison) and Lex tools to generate the parser and lexical analyzer, ...
0
votes
0
answers
27
views
Flex doesn't scan as I expect
Here are some define and rules in my lex.l:
id [_a-zA-Z][a-zA-Z0-9_]*
non_blank [^ \t\n]+
"(" { ECHO; }
")" { ECHO; }
{id} { printf("ID:%s "...
0
votes
0
answers
29
views
yacc returns without parsing full sentence
I am currently trying to write a parser in lex and yacc to parse all valid time formats. The relevant .l and .y codes are included below.
^[0-9]{1,2} { printf("HOUR: %s\n", yytext); return ...
2
votes
1
answer
67
views
I'm writing a simple calculator using Flex and Bison, but I keep encountering errors like missing library, unresolved reference
%option noyywrap
%{
#include "calculator.tab.h"
int yyerror(const char *);
%}
%%
[ \t]
[0-9]+ { yylval = atoi(yytext); return NUMBER; }
"+" ...
0
votes
0
answers
27
views
How to put tabs in the input of a lex program?
I am making a code in lex that identifies tokens and key word from another programming language. When i put my input i want to be able to introduce tabs so i can write a whole function but at the ...
-1
votes
1
answer
63
views
Input buffer overflow in scanner for long comments
I have defined a LEX scanner with the following rule for scanning (nested) comments:
"(*" {
int linenoStart, level, ch;
linenoStart = yylineno;
level = 1;
do {
ch = ...
0
votes
0
answers
71
views
CUP Error "Couldn't repair and continue parse"
Working on CUP. Here are my files:
A3.cup:
import java.io.*;
import java_cup.runtime.*;
/* Terminals (tokens returned by the scanner). */
terminal TIMES, DIVIDE, OPAREN, CPAREN, BEGIN, END, ...
0
votes
0
answers
66
views
Parsers and BNF grammar
So I making a grammar for turtle language but I have been stuck trying to define a grammar.I have tried to make multiple ones but these are the ones that seem alright to me but I have no idea whether ...
0
votes
0
answers
36
views
How to implement delimiters in Flex lexical analyzer [duplicate]
I am attempting to write a basic scanner using Flex. I want the identifiers to be starting with alphabets and contain alphabets and digits. The code I write for it is:
[A-Za-z][A-Za-z0-9]* {// ...
0
votes
1
answer
66
views
Yacc : Boolean and Arithmetic expression grammars conflict
I'm implementing a compiler as part of a class, for a language which is supposed to support both arithmetic and boolean expression. Unfortunately, I'm having some trouble implementing rules for both ...