Posted
almost 11 years
ago
by
mikedepriest
I've looked at several threads here, including this one:
https://irony.codeplex.com/discussions/499902
and I'm not sure how to proceed.
I am creating a custom grammar for calculations. Some of the terms I want to use in the calculations are
... [More]
variables whose names may have spaces embedded within them. In the Variable names are enclosed with braces {}, and their values are looked up externally for use in the calculation.
Here's a simplified example of a statement I'd like to use in my calculator:
1+MyFunction({A Variable With Spaces})+3
So far, I'm doing OK as long as I only use variables whose names don't have spaces. This, for example, works fine:
1+MyFunction({AVariableWithoutSpaces})+3
The grammar code for my variable is currently like this:
var myVariableName = new IdentifierTerminal("VariableName");
var myVariableExpr = new NonTerminal("MyVariableExpr", typeof(MyVariableNode));
var myVariableExpr.Rule = "{" + myVariableName + "}";
I sense from the response in https://irony.codeplex.com/discussions/499902 that instead of being an IdentifierTerminal, I need to subclass it or make my own version that allows embedded spaces - but I'm not sure how to do that, and let's just say I'm not the strongest C# programmer in the world. I can go by examples pretty well though.
Can anyone point me in the right direction?
[Less]
|
Posted
almost 11 years
ago
by
troncho
Hi, I've just downloaded the new version. I open the proyect under VS2010 and try to build just [010.Irony.2010]. It throws all this errors, because referenced files don't exist on the downloadable zip file:Error 1 Source file
... [More]
'...\Irony\Parsing\_new\GlrParser.cs' could not be opened ('Unspecified error ') 010.Irony.2010Error 2 Source file '...\Irony\Parsing\_new\NewScanner\NewScanner.cs' could not be opened ('Unspecified error ') 010.Irony.2010Error 3 Source file '...\Irony\Parsing\_new\NewScanner\SourceSegments.cs' could not be opened ('Unspecified error ') 010.Irony.2010Error 4 Source file '...\Irony\Parsing\_new\NewScanner\TerminalLookupByPrefix.cs' could not be opened ('Unspecified error ') 010.Irony.2010Error 5 Source file '...\Irony\Parsing\_new\NewScanner\_partialDefs.cs' could not be opened ('Unspecified error ') 010.Irony.2010I compared [010.Irony.2010.csproj] with the previous version and these new lines appear on the new release, which are not included in the downloadable zip file ([Parsing\_new] directory doesn't exist):101 <None Include="Parsing\_new\CompilerDirective\CompilerDirectiveBase.cs" /> 102 <None Include="Parsing\_new\CompilerDirective\IfDirective.cs" /> 103 <None Include="Parsing\_new\CompilerDirective\IfExpressionHandler.cs" /> 104 <None Include="Parsing\_new\CompilerDirective\_CompilerDirectiveTerminal.cs" /> 105 <None Include="Parsing\_new\CompilerDirective\MacroDirective.cs" /> 106 <Compile Include="Parsing\_new\GlrParser.cs" /> 107 <Compile Include="Parsing\_new\NewScanner\NewScanner.cs" /> 108 <Compile Include="Parsing\_new\NewScanner\SourceSegments.cs" /> 109 <Compile Include="Parsing\_new\NewScanner\TerminalLookupByPrefix.cs" /> 110 <Compile Include="Parsing\_new\NewScanner\_partialDefs.cs" /> May be I'm missing something. Thanks in advance :) [Less]
|
Posted
almost 11 years
ago
by
vermorel
Thanks a lot! It works.
|
Posted
almost 11 years
ago
by
schneiderr
Well, thats the problem. The script above is only very simplified grammar and other rules for memberFromExpression and memberForItemFunction are different. This is the only case which causes a problem.
All in all, thnx for ansver, I'll try to reorganize it somehow.
|
Posted
almost 11 years
ago
by
rivantsov
define identifier as 'usual' and then hook to identifier.ValidateToken event and write code that validates the identifier according to your rules
|
Posted
almost 11 years
ago
by
vermorel
I would like to create an ExcelIdentifier that would match Excel-like cell references, that is,
(correct) A1
(correct) B12
(correct) A3B7
(incorrect) A0
(incorrect) B1A1
(incorrect) A7B2
Who would you proceed to do this with Irony? I have looked at the implementation of the usual C# or Python identifiers, but it does not really feel relevant.
|
Posted
almost 11 years
ago
by
lalbatros
Thanks Roman.
I realized that I could resolve parameters before parsing.
Therefore, I would enjoy to make sure that the expressions being parsed are in the form a1x1+a2x2+...
where a1 and the like would be numbers and x1 and the like would be
... [More]
named variables.
Of course, the expression could also be created as a11*x1a12 or a11/a12x1/a12 and so on.
Maybe this should be resolved after parsing.
Thanks again for this nice package.
Michel
[Less]
|
Posted
almost 11 years
ago
by
rivantsov
These two look so similar that it does not seem reasonable to make them different things for parser. Just define one thing instead, let parser parse it and then distinguish them if needed analyzing the parse tree. Note that LALR parser in general is
... [More]
very limited in recognizing 'surrounding context' of a token and making judgement about proper variety of a node - mostly, just the next token and nothing else in decision. Do not overload parser with semantic decisions - it things are similar the way they look, they should be represented as one element in the grammar.
Roman
[Less]
|
Posted
almost 11 years
ago
by
rivantsov
what is 'linear expressions'?
now, at what point you need to distinguish between vars and parameters? during parsing, or after parsing in AST tree, or during execution at runtime? The easiest would be at runtime (I guess, not knowing what exactly
... [More]
you need). At runtime you can mark assigned values as 'parameters' in some way (save them in dictionary); you'll have to modify the language runtime and related classes for this. At parse time - have no idea, based on info you provided. Please give an example, sample source and what kind of different treatment you want (and at which stage) for vars vs params.
Roman
[Less]
|
Posted
almost 11 years
ago
by
rivantsov
I would recommend transforming parse tree, not AST tree. Examples - do not have any, just build a tree visitor/rewriter, that finds certain node patterns (nested AND expressions) and replaces them with a combined node representing AND function over multiple arguments.
|