How can I construct a clean, Python like grammar in ANTLR? -


G'day!

How can I create a simple ANTLR grammar to deal with a multi-line quote without semicolon or backslabs?

I'm trying to write a simple DSLs for expressions:

  # sh style comments ThisValue = 1 ThatValue = ThisValue * 2 ThisOtherValue = (1 + 2 + ThisValue * ThatValue) YetAnotherValue = MAX (ThisOtherValue, ThatValue)  

Overall, I want to provide the script with some initial designated values ​​in your application and exit end result . I would like to support multiple line manifestations like being hung on syntax, even though I have the following:

  # Note: the word is no backslash needed to continue because we are in brackets # Note: a semicolon at the end of the word is not necessary, either ThisValueWithAReallyLongName = (ThisOtherValueWithASimilarlyLongName + AnotherValueWithAGratuitouslyLongName)  

beginning with such an ANTLR grammar:

  exprlis T: (assignment_statement | empty_line) * EOF! ; Assignment_Statement: Assignment NL! ; Down_line: nl; Assignment: id '=' esp; // ... and so on  

It sounds simple, but I'm already in trouble with new lines:

  Warning (200 ): Stackoverflow question .g: 11: 20: Decision can match input like "NL" by using several options: 1, 2 result, optional (s) 2 to that input  
< P> was disabled, in ORg.antlr.works.IDE:

I have kicked grammar, but it always ends with a breach of expected behavior

  • Do not need a new line at the end of the file
  • Empty lines are acceptable
  • Everything from one pound sign to one line comment is discarded as
  • ends with the end of the line of work, not a semicolon
  • expressions many rows can span if wrapped in brackets

I can find example ANTLR grammar with many of these features. I think that when I cut them down to restrict them to their expression, then I have to break something very easy to others, and I broke them as adding them expression.

Which angle should I take with this grammar? Can you point to examples that are not equal or complete Turing-complete language?

"itemprop =" text ">

I will do my tokenizer doing big things in my grammar instead of mixing your New Line rules: < / P>

  • Count brackets, brackets, and braces, and do not generate nL tokens when there are no enclosed groups. It will continue the free line without any grammar intelligent.

  • Always generate an NL token at the end of the file, even if the last line is a '\ n' character, then you have a statement without NL There is no need to worry about the special case. The term always ends with a NL.

The other thing that make you simplify your grammar like this:

  exprlist: (Asainment_stetment | Rikt_lain) * Iof! ; Assignment_statement: assignment nl; Down_line: nl; Assignment: id '=' esp;  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -