grammar

What is the difference between LR, SLR, and LALR parsers?

What is the actual difference between LR, SLR, and LALR parsers? I know that SLR and LALR are types of LR parsers, but what is the actual difference as far as their parsing tables are concerned? And how to show whether a grammar is LR, SLR, or LALR? For an LL grammar we just have to show that any cell of the parsing table should not con...

Ambiguity in LL grammar

Considering the following grammar S -> iEtES'|a S'-> eS S'-> E-> b What will the value of FOLLOW(S'). I know that if there is a production fo the form `A->aB' then everything in FOLLOW(A) is in FOLLOW(B) but corresponsind to the above grammar FOLLOW(S') is same as FOLLOW(S) then what is FOLLOW(S)? Whether this rule will be applied fo...

Fixed number format in ANTLR

How to specify a fixed digit number in antlr grammar? I want to parse a line which contains fields of fixed number of characters. Each field is a number. 0034|9056|4567|0987|-2340| +345|1000 The above line is a sample line. | indicates field boundaries (which will not be in the actual file. shown here just to indicate the boundary). ...

Is the grammar LALR?

Lets say the same grammar is not LR(1), can we safely say that the grammar is not LALR too? if not, what are the conditions for a grammar to be LALR? (or what are the conditions that make a grammar not LALR) Thanks for the help! ...

Obtaining the lookahead token in LR(1)

I'm having a bit of trouble understanding how to obtain the lookahead token for LR(1). I'm hoping that someone can post a small example, and explain it to me. Thanks for the help! ...

Lookahead Token in LR(1)

P-> Q | ε Q-> m | m Q S0: S' ->.P, $ P -> .Q, $ P -> ., $ Q -> .m, $ Q -> .mQ, $ < Arrow from S0 to S2 moving with m> S2: Q-> m., $ Q-> m.Q, $ Q-> .m, $ Q-> .mQ, $ < Arrow from S2 to S3 moving with Q> S3: Q-> mQ., $/m Can someone explain how why the lookahead token "m" is in S3? Thanks a lot for the help! ...

Best solution for language documentation.

I'm developing a new object oriented scripting language and the project itself is quite ready for audience now, so i'm starting to think about a serious (not as "drafty" as it is right now) way of document its grammar, functions from standard library and standard library classes. I've looked a bit around and almost every language hash it...

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...

regular expression for bit strings with even number of 1s

Let L= { w in (0+1)* | w has even number of 1s}, i.e. L is the set of all bit strings with even number of 1s. Which one of the regular expressions below represents L? A) (0*10*1)* B) 0*(10*10*)* C) 0*(10*1)* 0* D) 0*1(10*1)* 10* According to me option D is never correct because it does not represent the bit string with zero 1s. But ...

Grammar/own-written parser?

Hello all, I'm doing some small projects which involve having different syntaxes for something, however sometimes these syntaxes are so easy that using a parser generator might be overkill. Now, when should I use a hand-made parser, and when should I use a parser generator? Thanks, William van Doorn ...

GNU Flex, multiline rule

Hi there i have a flex rule inside my lexer definition : operators "[]"|"[]="|"[]<"|".."|"."|".="|"+"|"+="|"-"|"-="|"/"|"/="|"*"|"*="|"%"|"%="|"++"|"--"|"^"|"^="|"~"|"&"|"&="|"|"|"|="|"<<"|"<<="|">>"|"!"|"<"|">"|">="|"<="|"=="|"!="|"&&"|"||"|"~=" Is there any way to split this ruole on more lines to keep it clearer? I tried with \ ju...

strip action code from bison grammar file

Hi Is there any existing tool to strip all the action code from bison grammar files, leaving only the {} around it? ...

C grammar in GCC source code

I'm looking for the C grammar in GCC source code, more specifically for the grammar in the yacc/bison form. ...

ANTLR - Embedding Java code, evaluate before or after?

Hello all, I'm writing a simple scripting language on top of Java/JVM, where you can also embed Java code using the {} brackets. The problem is, how do I parse this in the grammar? I have two options: Allow everything to be in it, such as: [a-z|a-Z|0-9|_|$], and go on Get an extra java grammar and use that grammar to parse that small ...

How to generate random html document

I'd like to generate completely random piece of html source, possibly from a grammar. I want to do this in python but I'm not sure how to proceed -- is there a library that takes a grammar and just randomly follows its rules, printing the path? Ideas? ...

Problem with Closure properties of context free languages

hello i have the following sentence a language L1={a^n * b^n : n>=0} and L2={b^n * a^n : n>=0} are context free languages so they are close a=under the L1L2 so L={a^n * b^2n A^n : n>=0} must be context free too because it is generated by a close property I have to prove if this sentence is true or not so i check the L language and i do...

What trick does Java use to avoid spaces in >> ?

In the Java Generic Book, while contrasting the difference between C++ Templates and Java Generic says: In C++, a problem arises because >> without the space denotes the right-shift operator. Java fixes the problem by a trick in the grammar.) What is this trick? ...

On ocamlyacc, function application grammar and precedence

I'm OCaml newbie and I'm trying to write a simple OCaml-like grammar, and I can't figure this out. My grammar allows something like this: let sub = fun x -> fun y -> x - y;; However, if I want to use the function so defined, I can write: (sub 7) 3 but I can't write sub 7 3, which really bugs me. For some reason, it gets interpreted as...

Is there a standard C++ grammar?

Does the standard specify the official C++ grammar? I searched, but did not find it anywhere. Also, I wish to read a bit about C++ grammar in detail, like which category of grammars it falls in, etc. Any links pointing me in the right direction would be helpful. By category, I mean taken from here. ...

Treetop: parsing single node returns nil

I'm trying to get the basic of Treetop parsing. Here's a very simple bit of grammar so that I can say ArithmeticParser.parse('2+2').value == 4. grammar Arithmetic rule additive first:number '+' second:number { def value first.value + second.value end } end rule number [1-9] [0-9]* { def value...