antlr3

ANTLR grammar for reStructuredText (rule priorities)

懵懂的女人 提交于 2019-11-30 13:33:08
问题 First question stream Hello everyone, This could be a follow-up on this question: Antlr rule priorities I'm trying to write an ANTLR grammar for the reStructuredText markup language. The main problem I'm facing is : "How to match any sequence of characters (regular text) without masking other grammar rules?" Let's take an example with a paragraph with inline markup: In `Figure 17-6`_, we have positioned ``before_ptr`` so that it points to the element *before* the insert point. The variable `

Nested Boolean Expression Parser using ANTLR

主宰稳场 提交于 2019-11-30 03:42:02
I'm trying to parse a Nested Boolean Expression and get the individual conditions within the expression separately. For e.g., if the input string is: (A = a OR B = b OR C = c AND ((D = d AND E = e) OR (F = f AND G = g))) I would like to get the conditions with the correct order. i.e., D =d AND E = e OR F = f AND G = g AND A = a OR B = b OR C = c I'm using ANTLR 4 to parse the input text and here's my grammar: grammar SimpleBoolean; rule_set : nestedCondition* EOF; AND : 'AND' ; OR : 'OR' ; NOT : 'NOT'; TRUE : 'TRUE' ; FALSE : 'FALSE' ; GT : '>' ; GE : '>=' ; LT : '<' ; LE : '<=' ; EQ : '=' ;

Scala parser combinators vs ANTLR/Java generated parser?

人盡茶涼 提交于 2019-11-30 03:00:58
I am writing an expression parser for an app written mostly in Scala. I have built AST objects in Scala, and now need to write the parser. I have heard of Scala's built-in parser combinators, and also of ANTLR3, and am wondering: which would provide better performance and ease of writing code? So far: ANTLR pros Well-known Fast External DSL ANTLRWorks (great IDE for parser grammer debugging/testing) ANTLR cons Java-based (Scala interop may be challenging, any experience?) Requires a large dependency at runtime Parser combinator pros Part of Scala One less build step No need for a runtime

How do I make a TreeParser in ANTLR3?

醉酒当歌 提交于 2019-11-29 11:35:10
I'm attemping to learn language parsing for fun... I've created a ANTLR grammar which I believe will match a simple language I am hoping to implement. It will have the following syntax: <FunctionName> ( <OptionalArguments>+) { <OptionalChildFunctions>+ } Actual Example: ForEach(in:[1,2,3,4,5] as:"nextNumber") { Print(message:{nextNumber}) } I believe I have the grammar working correctly to match this construct, and now I am attemping to build an Abstract Syntax Tree for the language. Firstly, I must admit I'm not exactly sure HOW this tree should look. Secondly, I'm at a complete loss how to

Why my antlr lexer java class is “code too large”?

冷暖自知 提交于 2019-11-29 10:50:45
This is the lexer in Antlr (sorry for a long file): lexer grammar SqlServerDialectLexer; /* T-SQL words */ AND: 'AND'; BIGINT: 'BIGINT'; BIT: 'BIT'; CASE: 'CASE'; CHAR: 'CHAR'; COUNT: 'COUNT'; CREATE: 'CREATE'; CURRENT_TIMESTAMP: 'CURRENT_TIMESTAMP'; DATETIME: 'DATETIME'; DECLARE: 'DECLARE'; ELSE: 'ELSE'; END: 'END'; FLOAT: 'FLOAT'; FROM: 'FROM'; GO: 'GO'; IMAGE: 'IMAGE'; INNER: 'INNER'; INSERT: 'INSERT'; INT: 'INT'; INTO: 'INTO'; IS: 'IS'; JOIN: 'JOIN'; NOT: 'NOT'; NULL: 'NULL'; NUMERIC: 'NUMERIC'; NVARCHAR: 'NVARCHAR'; ON: 'ON'; OR: 'OR'; SELECT: 'SELECT'; SET: 'SET'; SMALLINT: 'SMALLINT';

Antlr rule priorities

只谈情不闲聊 提交于 2019-11-29 10:43:13
Firstly I know this grammar doesn't make sense but it was created to test out the ANTLR rule priority behaviour grammar test; options { output=AST; backtrack=true; memoize=true; } rule_list_in_order : ( first_rule | second_rule | any_left_over_tokens)+ ; first_rule : FIRST_TOKEN ; second_rule: FIRST_TOKEN NEW_LINE SECOND_TOKEN NEW_LINE; any_left_over_tokens : NEW_LINE | FIRST_TOKEN | SECOND_TOKEN; FIRST_TOKEN : 'First token here' ; SECOND_TOKEN : 'Second token here'; NEW_LINE : ('\r'?'\n') ; WS : (' '|'\t'|'\u000C') {$channel=HIDDEN;} ; When I give this grammar the input 'First token here

Assembly's manifest definition does not match assembly reference

随声附和 提交于 2019-11-29 09:21:20
I updated all the packages of my MVC project and I got the following error: Could not load file or assembly 'Antlr3.Runtime, Version=3.5.0.2, Culture=neutral, PublicKeyToken=eb42632606e9261f' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) Building the project with a razor (.cshtml) file open gave me more errors Here's how I managed to solve it: Go to the solution explorer and choose Antlr under References, right-click and say properties. Make sure the file version is the same the compiler is

Get original text of an Antlr rule

白昼怎懂夜的黑 提交于 2019-11-29 04:36:25
I am an ANTLR beginner and want to calculate a SHA1-Hash of symbols. My simplified example grammar: grammar Example; method @after{calculateSha1($text); }: 'call' ID; ID: 'A'..'Z'+; WS: (' '|'\n'|'\r')+ {skip(); } COMMENT: '/*' (options {greedy=false;}: .)* '*/' {$channel=HIDDEN} As the lexer removes all whitespaces the different strings callABC , call /* DEF */ ABC unfortunately get the same SHA1-Hash value. Is it possible to get the "original" text of a rule between the start- and end-token with all the skipped whitespaces and the text of the other channels? (One possibility that comes into

Nested Boolean Expression Parser using ANTLR

牧云@^-^@ 提交于 2019-11-29 02:43:47
问题 I'm trying to parse a Nested Boolean Expression and get the individual conditions within the expression separately. For e.g., if the input string is: (A = a OR B = b OR C = c AND ((D = d AND E = e) OR (F = f AND G = g))) I would like to get the conditions with the correct order. i.e., D =d AND E = e OR F = f AND G = g AND A = a OR B = b OR C = c I'm using ANTLR 4 to parse the input text and here's my grammar: grammar SimpleBoolean; rule_set : nestedCondition* EOF; AND : 'AND' ; OR : 'OR' ;

Scala parser combinators vs ANTLR/Java generated parser?

谁说胖子不能爱 提交于 2019-11-29 00:37:55
问题 I am writing an expression parser for an app written mostly in Scala. I have built AST objects in Scala, and now need to write the parser. I have heard of Scala's built-in parser combinators, and also of ANTLR3, and am wondering: which would provide better performance and ease of writing code? So far: ANTLR pros Well-known Fast External DSL ANTLRWorks (great IDE for parser grammer debugging/testing) ANTLR cons Java-based (Scala interop may be challenging, any experience?) Requires a large