bnf

BNF to standard EBNF

こ雲淡風輕ζ 提交于 2019-12-13 07:30:49
问题 I am converting BNF dialect 2 to standard EBNF and making the grammar as simple as possible from this problem below. <state> -> <abc> | <abc>; <state> -> <def> | <def>; <state> -> <ghi> | <ghi>; here is my attempt that I followed along page 131 in my textbook http://umsl.edu/~mfrp9/misc/cpl.pdf <state> -> (<abc> | <abc>)(<def> | <def)(<ghi> | <ghi>); Is this a correct solution and is there a simpler solution than this with {...} for repeated? Also I noticed in this post How to convert BNF to

Operator Associativity

自古美人都是妖i 提交于 2019-12-13 07:04:54
问题 I have the following EBNF expression grammar: <expr> -> <term> { (+|-) <term> } <term> -> <factor> { (*|/|%) <factor> } <factor> -> <pow> { ** <pow> } <pow> -> ( <expr> ) | <id> <id> -> A | B | C I need to determine if the grammar enforces any particular associativity for its operators, or if that would have to be implemented in the parser code. From what I have read so far, it doesn't look like it does, but I am having a hard time understanding what causes associativity. Any help would be

JAVA BNF “no short if” - what does this mean?

瘦欲@ 提交于 2019-12-13 05:36:45
问题 Basically the title. Looking through the Java BNF, I see "no short if" such as in: <statement no short if> ::= <statement without trailing substatement> | <labeled statement no short if> | <if then else statement no short if> | <while statement no short if> | <for statement no short if> What does it "no short if" mean? I see "NoShortIf" popping up in my lecture slides with no explanation of what it means. 回答1: The answer is in the link provided above in the comment by @Andy Turner: Statements

How to write the BNF for this tree-related operation?

孤街醉人 提交于 2019-12-13 02:42:24
问题 We have a tree like this: We can convert it to a dotstring representation , i.e., Such a tree can be represented by the preorder sequence of its nodes in which dots (.) are inserted where an empty subtree (nil) is encountered during the tree traversal. So we can convert the tree in the picture to 'abd..e..c.fg...' . If I am about to write a function to do this conversion, what's the BNF or syntax diagrams of it? 回答1: It's not clear what you're asking. If you think of the string as a sentence

Can't figure out why Bison is throwing “Rules useless in parser due to conflicts”

一个人想着一个人 提交于 2019-12-12 12:11:42
问题 I'm writing a BNF grammar for a very simple programming language and using Flex and Bison to compile. I only have 3 variable and constant types: real, integer, string . My .l file has a token definition for "ID" as follows: DIGIT [0-9] LETTER [a-zA-Z] ID {LETTER}({LETTER}|{DIGIT})* My .y file has a definition for an identifier like this: identifier: ID; Now, I want to use the identifier definition to build variable and constant names. But I also want to limit assignment to data of the same

[af]?lex regular expression difference

陌路散爱 提交于 2019-12-12 06:39:41
问题 I don't know how to do this, and I've found no good resources online for how to perform this operation[.] I'm trying to take an annotated EBNF production rule which is a difference between two regular expressions and turn it into a(n a| f?)lex grammar specification rule[.] The problem is that I see no way to do this normally[.]{3} is there a way to do this using Kleene algebra, like the way you can use an empty match with alternation in a context-free grammar[?] 回答1: What does the EBNF

ParseKit greedy matching mode

南楼画角 提交于 2019-12-11 12:56:23
问题 I am making something like formula validator and I am using ParseKit framework to accomplish that. My approach is to create proper grammar and when didMatchFormula callback method is called on sample string I assume formula has been found and therefore it is valid. There is one difficulty however - formula is detected from sample string even if it contains also other characters following formula part. I would need something like greedy mode for matching - an entire string would be matched

What is the best way to define grammars for a text editor?

心已入冬 提交于 2019-12-10 20:13:42
问题 I'm masochistically writing an open-source text editor for Mac and have finally reached the point at which I want to add syntax highlighting. I've been going back and forth on various solutions for the past few days, and I've finally decided to open the question to a wider audience. Here are the options I see: Define languages basically with a series of regex pattern matching (similar to how TextMate defines its languages) Define languages with a formal grammar like BNF or PEG Using regex

Generate BNF diagrams from an antlr grammar?

家住魔仙堡 提交于 2019-12-10 10:41:34
问题 I may well be asking something not achievable here.. Maybe someone can point out either (a) What would be some steps (/tools?) to at least partially achieve creation of bnf diagrams from a (rather complex) antlr grammar (b) why (if it were the case) this simply can not be achieved. E.g. maybe since antlr is extended BNF and its recursive structure differs from bnf requirements.. Along those lines. 回答1: ANTLRWorks 1 works for generating diagrams, one at a time, for rule. for v4, ANTLRWorks 2

Improve BNF for mathematic expressions

牧云@^-^@ 提交于 2019-12-09 13:48:29
问题 A good exercise while learning programming, is to write a calculator. To do this, I created some kind of DSL in BNF and want to ask for your help to improve it. With this minilanguage you should be able to add , multiply and assign values and expressions to names (a.k.a. create variables and functions). Hava a look at the BNF first: <Program> ::= <Line>(<NewLine><Line>)* <Line> ::= {"("}<Expression>{")"}|<Assignment> <Assignment> ::= <Identifier>"="<Expression> <Identifier> ::= <Name>{"("