grammar

I need help translating this portion of the ECMAScript grammar?

I've been working on my own implementation of ECMAScript for quite some time now. I have basically done everything by hand to help gain a deep understanding of the process. Repeated attempts to analyze and understand this portion of the grammar have failed so I've been working on other portions of the project but now I am at a point were...

Natural language grammar and user-entered names

Some languages, particularly Slavic languages, change the endings of people's names according to the grammatical context. (For those of you who know grammar or studied languages that do this to words, such as German or Russian, and to help with search keywords, I'm talking about noun declension.) This is probably easiest with a set of e...

The Definition of Regular Languages

Good Day, I have tried, and burned my brain to understand the definition of Regular Languages in Discrete Mathematics and its Applications(Rosen) without reaching the goal of understanding why the definition is like that in this book. On page(789), I am rephrasing the definition: Type 3 grammars are defined as: w1 --> w2 Where w1 is...

How to write a bison grammer for WDI?

I need some help in bison grammar construction. From my another question: I'm trying to make a meta-language for writing markup code (such as xml and html) wich can be directly embedded into C/C++ code. Here is a simple sample written in this language, I call it WDI (Web Development Interface): /* * Simple wdi/html sample source cod...

Specifying Language for a grammar

Hi All, Is there any specific methodology followed to specify a language for given grammar ?? i.e. Is it necessary to run all the production rules given in a grammar to determine the language it represents? I don't have an example as such since the one I am working on is a homework question. [edit]: adding an example, Describe, in Engl...

BNF to handle escape sequence

I use this BNF to parser my script: ` {identset} = {ASCII} - {"\{\}}; //<--all ascii charset except '\"' '{' and '}' {strset} = {ASCII} - {"}; ident = {identset}*; str = {strset}*; node ::= ident "{" nodes "}" | //<--entry point "\"" str "\"" | ident; nodes ::= node nodes | ...

Parsing blocks of line comments using MGrammar

How can I parse blocks of line comments with MGrammar? I want to parse blocks of line comments. Line comments that are next to each should grouped in the MGraph output. I'm having trouble grouping blocks of line comments together. My current grammar uses "\r\n\r\n" to terminate a block but that will not work in all cases such as at end...

ANTLR: simple example from ANTLRWorks wizard doesn't work

Grammar: grammar test; WS : ( ' ' | '\t' | '\r' | '\n' ) {$channel=HIDDEN;} ; STRING : '"' ( ESC_SEQ | ~('\\'|'"') )* '"' ; fragment HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ; fragment ESC_SEQ : '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\') | UNICODE_ESC | OCTAL_ESC ;...

What does =*> mean with regards to context free grammars?

I've been reading a couple books/online references about compiler theory, and keep seeing that particular operator coming up every once in a while (as seen here), specifically when the current topic is context free grammars. What does it mean? As well, how does it differ from =>? Explanations with examples distinguishing => from =*> wou...

Which is the best counterpart to ANTLR to create parsers in ruby?

Hi there, I've used antlr and javacc/freecc for a while. Now I need to write a bunch of parsers using antlr grammars but such parsers need to be written in ruby lang. I googled but nothing found. Is there any ruby parser generator that takes antlr grammars and create a parser? If there are many, which is the best one in your opinion? T...

How do I best do balanced quoting with Perl's Regexp::Grammars?

Using Damian Conway's Regexp::Grammars, I'm trying to match different balanced quoting ('foo', "foo", but not 'foo") mechanisms -- such as parens, quotes, double quotes, and double dollars. This is the code I'm currently using. <token: pair> \'<literal>\'|\"<literal>\"|\$\$<literal>\$\$ <token: literal> [\S]+ This generally ...

Are there programs that iteratively write new programs?

For about a year I have been thinking about writing a program that writes programs. This would primarily be a playful exercise that might teach me some new concepts. My inspiration came from negentropy and the ability for order to emerge from chaos and new chaos to arise out of order in infinite succession. To be more specific, the ...

Grammar checking API?

Are there any APIs that check the grammar of a given string? If so can you give examples? ...

How does the right-shift operator work in a python print statement?

I've seen someone using "print" with ">>" to write stuffs into a file: In [7]: with open('text', 'w') as f: ...: print >> f, "Hello, world!" ...: In [8]: !type text Hello, world! How does it work? When should I use this instead of just using the "write" method? ...

How to read alternates in EBNF grammars

I have an EBNF grammar that has a few rules with this pattern: sequence ::= item | item extra* sequence Is the above equivalent to the following? sequence ::= item (extra* sequence)* Edit Due to some of you observing bugs or ambiguities in both sequences, I'll give a specific example. The SVG specification provides a g...

vxml: need help with in-line grammars

I am looking at some sample vxml scripts from vxml.org. When i call the script the prompts play, but it doesnt pick up any of my inputs at all. when i speak it responds "no input". could i be missing some tag that indicates input from the user. this is the example script from the website: <?xml version="1.0" encoding="UTF-8"?> <vxml ver...

Converting ambiguous grammar to unambiguous

I did not understand how a unambiguous grammar is derived from a ambiguous grammar? Consider the example on site: Example. How was the grammar derived is confusing to me. Can anyone please guide me ? ...

Why is the Alternative symbol of the ECMAScript RegExp grammar left recursive?

I cannot for the life of me figure out why Alternative is left recursive. It really throws a wrench into my parser. Alternative :: [empty] Alternative Term Here is a note in the semantics portion of the spec that is not exactly clear. Maybe the reasoning would be revealed once I understand this? NOTE Consecutive Terms ...

How does Python variable scoping works?

This wants me to dig deeper in Python sources, but since there are many people on SO that already done that, I would love to hear their pointers. >>> import os >>> def scope(): ... print os ... import os ... >>> scope() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 2, in scope U...

Programmatically derive a regular expression from a string.

I would like to input a string and return a regular expression that can be used to describe the string's structure. The regex will be used to find more strings of the same structure as the first. This is intentionally ambiguous because I will certainly miss a case that someone in the SO community will catch. Please post any and all po...