grammar

Antrl3 conditional tree rewrites

痴心易碎 提交于 2019-12-07 17:31:52
问题 Stackoverflow. Continuing on my journey into Antlr (Previous questions may provide additional clues on what I'm trying to achieve! Q1 - How do I make a tree parser and Q2 - Solving LL recursion problem) I've hit yet another roadblock I cannot flathom. Basically (I believe) the expression rule in my grammar needs to either create a new root node depending on the number of datatype s it has matched. I have put together an example to try best describe what I mean: Given the following input:

Translate ANTLR grammar into XText grammar: how to remove syntactic predicates

风格不统一 提交于 2019-12-07 16:59:19
问题 I'm new to both Xtext and ANTLR. I need to translate an ANTLR (.g) grammar into an XTEXT (.xtext) grammar. In the ANTLR grammar there are syntactic predicates which are not supported by Xtext. Is there a way to remove/translate these predicates? Thanks EDIT The ANTLR grammar which I'm trying to translate can be found here: /* * Copyright 2009, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that

Grammar for expressions which disallows outer parentheses

て烟熏妆下的殇ゞ 提交于 2019-12-07 16:17:04
问题 I have the following grammar for expressions involving binary operators (| ^ & << >> + - * /): expression : expression BITWISE_OR xor_expression | xor_expression xor_expression : xor_expression BITWISE_XOR and_expression | and_expression and_expression : and_expression BITWISE_AND shift_expression | shift_expression shift_expression : shift_expression LEFT_SHIFT arith_expression | shift_expression RIGHT_SHIFT arith_expression | arith_expression arith_expression : arith_expression PLUS term |

Free-form text with custom SRGS based Grammar

自古美人都是妖i 提交于 2019-12-07 15:48:39
问题 I am trying to develop a Voice based application that would accept user input as speech and perform some actions based on the input. This is my first ever venture into this technology and I am learning while developing it. I am using Microsoft SAPI shipped with dotnet 4 to recognize speech. So far, I have learned about the two types of modes it supports. Speech recognition (SR) has two modes of operation: Dictation mode — an unconstrained, free-form speech interpretation mode that uses a

XText: use custom terminals definitions

前提是你 提交于 2019-12-07 15:24:31
问题 I'm totally new to XText. When you define a grammar using XText you could specify a second grammar and use the definitions it declares as it is said here: grammar org.eclipse.xtext.example.Domainmodel with org.eclipse.xtext.common.Terminals In Xtext each grammar has a unique name, which like public Java classes needs to reflect the location of the file within the Java classpath. In our case the grammar file is located in /org/eclipse/xtext/example/Domainmodel.xtext therefore the name of the

String Template: make all variable declaration global

元气小坏坏 提交于 2019-12-07 13:53:12
问题 I am trying to implement a translator using ANTLR+StringTemplate. I have a starting language that is java like and multiple destination language. I used the example: http://www.antlr.org/wiki/display/ST/Language+Translation+Using+ANTLR+and+StringTemplate One of my destination language needs all variables to be declared globally. I wrote a grammar that recognizes variables, but i cannot find e way in my template for making a local variable to be declared globally. Of course if I would have

C++: difference between 0. and 0.0?

╄→尐↘猪︶ㄣ 提交于 2019-12-07 12:53:13
问题 I am well aware of the difference between 0 and 0.0 (int and double). But is there any difference between 0. and 0.0 ( please note the . )? Thanks a lot in advance, Axel 回答1: There is no difference. Both literals are double. From the C++-Grammar: fractional-constant: digit-sequenceopt . digit-sequence digit-sequence . See: Hyperlinked C++ BNF Grammar 回答2: No, there is not. 回答3: No. You can also write .0 as far as I know. 回答4: Just having the . as part of the number identifies it as a floating

Parsing python with PLY, how to code the indent and dedent part

孤人 提交于 2019-12-07 11:32:08
问题 I was trying to parse the function definition for the python language with PLY. I am encountering issues related to the indentation. For instance for a for statement, I would like to be able to know when the block ends. I read the python grammar here: http://docs.python.org/2/reference/grammar.html And the grammar for this part is: for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT I don't know how to describe the INDENT and

boost::Spirit Grammar for unsorted schema

怎甘沉沦 提交于 2019-12-07 10:46:30
问题 I have a section of a schema for a model that I need to parse. Lets say it looks like the following. { type = "Standard"; hostname="x.y.z"; port="123"; } The properties are: The elements may appear unordered. All elements that are part of the schema must appear, and no other. All of the elements' synthesised attributes go into a struct. (optional) The schema might in the future depend on the type field -- i.e., different fields based on type -- however I am not concerned about this at the

ANTLR Implicit Multiplication

非 Y 不嫁゛ 提交于 2019-12-07 07:07:06
问题 I'm new to ANTLR, and I'm trying to expand upon the example of a simple calculator presented here. Specifically, I've tried adding some simple functions, negative numbers and so on, to familiarize myself with ANTLR. However, I've run into a bit of a problem trying to implement "implicit" multiplication (for example, 3cos(2)sin(2) would be interpreted as 3*cos(2)*sin(2)). I've found a question on Stack Overflow with the same kind of problem (here). The general form of the solution to that