Class StandardStructuredParser
- java.lang.Object
-
- com.singularsys.jep.configurableparser.ConfigurableParser
-
- com.singularsys.extensions.structure.StructuredParser
-
- com.singularsys.extensions.structure.StandardStructuredParser
-
- All Implemented Interfaces:
JepComponent
,Parser
,java.io.Serializable
public class StandardStructuredParser extends StructuredParser
A structured parser with a java like grammar. Supports java stylefor
,while
,if
structures, sequences of expressions and blocks using{ ... }
,break
andcontinue
statements and aprint
statement.for(i=0;i<10;i=i+1) { if(x % 2 ==0 ) x=x+i; }
The set up for this parser is
this.addSlashComments(); this.addDoubleQuoteStrings(); this.addWhiteSpace(); this.addExponentNumbers(); this.addOperatorTokenMatcher(); this.addSymbols(new String[]{"(",")","[","]","{","}",",",";", "for","while","break","continue","if","else"}); this.setImplicitMultiplicationSymbols(new String[]{"(","["}); this.addIdentifiers(); this.addWhiteSpaceCommentFilter(); this.addBracketMatcher("(",")"); this.addFunctionMatcher("(",")",","); this.addListMatcher("[","]",","); this.addArrayAccessMatcher("[","]"); SymbolToken ropen = getSymbolToken("("); SymbolToken rclose = getSymbolToken(")"); SymbolToken copen = getSymbolToken("{"); SymbolToken cclose = getSymbolToken("}"); SymbolToken forTok = getSymbolToken("for"); SymbolToken whileTok = getSymbolToken("while"); SymbolToken breakTok = getSymbolToken("break"); SymbolToken continueTok = getSymbolToken("continue"); SymbolToken ifTok = getSymbolToken("if"); SymbolToken elseTok = getSymbolToken("else"); SymbolToken semi = getSymbolToken(";"); // Rule for expressions handled by the Configurable parser ExpressionRule expr = new ExpressionRule(); // Expression terminated by a semi colon //TerminatedExpressionRule texpr = new TerminatedExpressionRule(expr,semi); PossiblyTerminatedExpressionRule pexpr = new PossiblyTerminatedExpressionRule(expr,semi); // A single statement, represents a list of possibilities StatementRule statement = new StatementRule(); // A sequence of one of more statements SequenceRule seq = new SequenceRule(statement); // A block of code surrounded by { and } BlockRule blockRule = new BlockRule(copen,seq,cclose); statement.addRule(blockRule); // An if statement: if( expression ) statement else JavaIfRule ifRule = new JavaIfRule(ifTok,ropen,expr,rclose,statement,elseTok); statement.addRule(ifRule); // A wile statement: while( expression ) statement JavaWhileRule whileRule = new JavaWhileRule(whileTok,ropen,expr,rclose,statement); statement.addRule(whileRule); // a for statement: for( expression ; expression ; expression ) statement JavaForRule forRule = new JavaForRule(forTok,ropen,expr,semi,rclose,statement); statement.addRule(forRule); // a break statement: break; ControlRule breakRule = new ControlRule(breakTok,semi,ControlValues.BREAK); statement.addRule(breakRule); // a continue statement: continue; ControlRule contRule = new ControlRule(continueTok,semi,ControlValues.CONTINUE); statement.addRule(contRule); // Add the terminated expression statement.addRule(pexpr); // Sets the rules, parameters are the head rule // and the rule used for parsing an expression setStructuredRules(seq);
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description StandardStructuredParser()
-
Method Summary
-
Methods inherited from class com.singularsys.extensions.structure.StructuredParser
getStructuredRules, setStructuredRules
-
Methods inherited from class com.singularsys.jep.configurableparser.ConfigurableParser
addArrayAccessMatcher, addBracketMatcher, addDoubleQuoteStrings, addExponentNumbers, addFunctionMatcher, addGrammarMatcher, addHashComments, addIdentifiers, addListMatcher, addListOrBracketMatcher, addOperatorTokenMatcher, addSemiColonTerminator, addSimpleNumbers, addSingleQuoteStrings, addSlashComments, addSymbols, addTokenFilter, addTokenMatcher, addWhiteSpace, addWhiteSpaceCommentFilter, continueParse, filter, getGrammarMatchers, getGrammarParserFactory, getJep, getLightWeightInstance, getOperatorTokenMatcher, getSymbolToken, getSymbolTokenMatcher, getTokenFilters, getTokenizerFactory, getTokenMatchers, init, parse, parse, restart, scan, scan, setGrammarParserFactory, setImplicitMultiplicationSymbols, setTokenizerFactory
-
-