1,836 questions
4
votes
1
answer
178
views
How does yacc parse C fragments?
I'm writing a parser, using yacc, similar to yacc itself, in that my input language will contain interspersed scraps of C code.
Consider the canonical sort of yacc production:
something: some thing { $...
2
votes
1
answer
157
views
Using %define api.prefix in bison/lex raises error in gcc when linking files
I'm using this answer as my template to add the prefix "eval": https://stackoverflow.com/a/48879103/14956120
The only difference from that answer, is that I'm on windows (using msys2), and ...
4
votes
2
answers
79
views
Lex Setup Correctly Validating Assignments but not Expressions
I recently revisited an old assignment that I did not get to work and I am still curious as to why it isn't.
This assignment was to create a lex regular expression in C that would validate both ...
0
votes
1
answer
73
views
AST creation segfaults when input string input is larger than 9
Test Ouputs:
./parse -r
/[123456]/
Accepted!
./parse -r
/[1234567]/
zsh: segmentation fault (core dumped) ./parse -r
This is my flex rule for the token.
\[^?([^\\\]]|\\.)*\] {yylval.value = strdup(...
0
votes
1
answer
91
views
how to resolve a shift/reduce conflict in bison?
I want to make a compilator for a language similar to C.
Declarations go first, then functions.
Declarations can only be "int" while functions can return "int" or "void".
...
0
votes
1
answer
90
views
Use flex to parse ":" and ".:" in expressions
I have a lex file, and based on the original, I would like to add support for recognizing (.:). My modifications are as follows:
%option caseless
ALP [a-z]+
NUM [0-9]+
REF {ALP}{NUM}
...
1
vote
0
answers
56
views
Assigning order attribute
An example circuit assignment looks like this:
A= B or C xor K.
When an identifier is undeclared its error message should be printed with the seen order left to right. To do so I attached an ...
0
votes
1
answer
62
views
Interactive input EOF (End of File) waiting problem in lex and yacc
The below is my two files:
calc.l
%{
#include "y.tab.h"
%}
%%
[0-9]+ { yylval = atoi(yytext); return NUMBER; }
[ \t\n ] ;
"+" { return '+'; }
"*" { return '*'; }
&...
0
votes
1
answer
106
views
Using lex and bison together with swift from Xcode
I'm working on integrating Swift with a simple parser generated using lex and bison in an Xcode 16.1 project.
Below is my current code:
calc.l
%{
#include "calc.tab.h"
#include <stdlib.h&...
0
votes
0
answers
64
views
Regex Derivative DFA: This Should Work, But It's Breaking in Unexpected Ways
I’m working on a DFA-based lexer using regex derivatives for tokenizing lexemes. I've built a setup that, theoretically, should handle regex simplification and DFA transitions accurately. For the most ...
0
votes
1
answer
93
views
Issue with Bison Parser for Handling for Loops (Syntax Error)
I am writing a parser using a context-free grammar with Bison and Flex to handle a simple language that includes for loops. However, I'm encountering a syntax error when I try to parse valid for loop ...
1
vote
1
answer
64
views
Priority Issues - Use LEX to write regular expressions to match strings of specific patterns
I try to write regular definitions to display the line of string for the following
using LEX.
a.Match any string starting with d, and ending with t
b. Matches the string def
c.Match one or more ...
0
votes
1
answer
67
views
Parsing only macro calls using Lex and Yacc
I am trying to build a parser that will only parse C++ macro calls in a code-base and store the arguments in the macro calls for further processing. In that code-base, it is known that macros contain ...
0
votes
0
answers
59
views
How to treat extended ASCII chars using lex? [duplicate]
I am trying to treat extended ascii characters with lex, e.g., àÀ.
%{
#include <stdio.h>
%}
DIGIT [0-9]
ALPHA_CHAR [A-Za-z]
EXTENDED [àÀ]
CHAR {ALPHA_CHAR}|{...
0
votes
0
answers
102
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 ...