this is a lab assignment i am stuck on. i cant believe i am having problems with this basic programming, but i cant afford to waste any more time on this. i gotta ask the experts.
i need to accept this grammar (ab)*b, which basically means any number of "ab" and ending with b.
i have written this code but somehow, it checks only the fi...
I'd like to perform some convoluted variation of the @a = @b || @c assignment, with the intent of taking @b if non-empty (hence true in a boolean sense), @c otherwise. The documentation explicitely tells me I can't. (And it's right about the fact, too!)
The "||", "//" and "&&" operators return the last value evaluated
(unlike C's...
I have a parser and lexer written in ocamlyacc and ocamllex. If the file to parse ends prematurely, as in I forget a semicolon at the end of a line, the application doesn't raise a syntax error. I realize it's because I'm raising and catching EOF and that is making the lexer ignore the unfinished rule, but how should I be doing this to r...
I'm trying to implement a expression handling grammar (that deals with nested parenthesis and stuff). I have the following so far, but they can't deal with some cases (successful/failure cases appear after the following code block). Anyone know what's going on?
Note: The varname += and varname = stuff are just some additional AST genera...
Does anyone know where the code TextMate uses for syntax highlighting is burried? If not, do you know how they parse their language syntaxes, or how you would parse their language syntaxes?
That would be awesome to look into.
Thanks!
Lance
...
I'm planning to write a C# 3.0 compiler in C#. Where can I get the grammar for parser generation?
Preferably one that works with ANTLR v3 without modification.
...
Hi,
I have a task to write a (toy) parser for a (toy) grammar using OCaml and not sure how to start (and proceed with) this problem.
Here's a sample Awk grammar:
type ('nonterm, 'term) symbol = N of 'nonterm | T of 'term;;
type awksub_nonterminals = Expr | Term | Lvalue | Incrop | Binop | Num;;
let awksub_grammar =
(Expr,
funct...
How to eliminate left recursion for the following grammar?
E := EE+|EE-|id
Using the common procedure:
A := Aa|b
translates to:
A := b|A'
A' := ϵ| Aa
Applying this to the original grammar we get:
A = E, a = (E+|E-) and b = id
Therefore:
E := id|E'
E' := ϵ|E(E+|E-)
But this grammar seems incorrect because
ϵE+ -> ϵ id +
w...
Perl has been one of my go-to programming language tools for years and years. Perl 6 grammars looks like a great language feature. I'd like to know if someone has started something like this for Ruby.
...
I wonder how to determine the FIRST set of E with grammar:
E -> XYE | e
X -> x
Y -> y
Can anyone give me some direction?
...
Could someone please give me some advice/ideas about how to deal with the situations when it's needed to have a look at further declarations to be able to make correct semantic actions on current moment? For example, it is a well-known occurrence when someone writes an interpreter/compiler of some programming language which doesn't suppo...
grammar Test;
IDHEAD: ('a'..'z' | 'A'..'Z' | '_');
IDTAIL: (IDHEAD | '0'..'9');
ID: (IDHEAD IDTAIL*);
fragment
TYPE: ('text' | 'number' | 'bool');
define: 'define' ID 'as' TYPE;
The problem is that the define rule matches the tokens define, ID, as, but wont match TYPE. I'm yielding a MissingTokenException.
If I inline the TYP...
What is a regexp that accepts everything over the language {0,1} but has no substring 110 or 101?
Accept:
111111
000011111
100001000001001
010
1
Reject:
100110
010100
123
Edit: Per comments on answers below, this question is asking for a formal regular expression.
...
Throughout a Bison grammar I am using right recursion, and I have read that left recursion is better because it doesn't have to build the whole stack first.
However, when I try to switch to left recursion on any of them, I always end up with a lot of conflicts, and I am not seeing why.
Can anyone show me a generic example of where usin...
I just came across this question in the Go FAQ, and it reminded me of something that's been bugging me for a while. Unfortunately, I don't really see what the answer is getting at.
It seems like almost every non C-like language puts the type after the variable name, like so:
var : int
Just out of sheer curiosity, why is this? Are t...
I have an ANTLR grammar for a simple DSL, and everything works swimmingly when there are no syntax errors. Now, however, I need to support an auto-completion mechanism, where I need to get possible completions from my tree grammars that perform basic type-checking on attributes, functions, etc.
The problem is, ANTLR isn't reporting syn...
I have a set of XML documents that all share the same schema. (They're SAPI grammars with semantic tags, if that matters.) I can use the documents to match text strings, returning a set of attributes with known values.
My problem is that I'd like to take a set of attribute values and generate a string from the grammar that (when sub...
I made a program that is supposed to recognize a simple grammar. When I input what I think is supposed to be a valid statement, I get an error. Specifically, if I type
int a;
int b;
it doesn't work. After I type int a; the program echoes ; for some reason. Then when I type int b; I get syntax error.
The lex file:
%{
#include <st...
In my yacc file I have things like the following:
var_declaration : type_specifier ID ';'
| type_specifier ID '[' NUM ']' ';' ;
type_specifier : INT | VOID ;
ID, NUM, INT, and VOID are tokens that get returned from flex, so yacc has no problems recognizing them. The problem is that in the above there are things like ...
I made a program that is supposed to recognize a simple grammar. When I input what I think is supposed to be a valid statement, I get an error. Specifically, if I start out with an identifier, I automatically get a syntax error. However, I noticed that using an identifier won't generate an error if it is preceded by 'int'. If a is an...