remove expr ambiguity
This commit is contained in:
		
							parent
							
								
									1f8008717b
								
							
						
					
					
						commit
						e5ab8b2db7
					
				| 
						 | 
					@ -1,23 +1,26 @@
 | 
				
			||||||
grammar Basic;
 | 
					grammar Basic;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
program: expr;
 | 
					program: expr EOF;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
expr
 | 
					expr
 | 
				
			||||||
 | 
					    : singleExpr (COMPOUND singleExpr?)*
 | 
				
			||||||
 | 
					    ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					singleExpr
 | 
				
			||||||
    : PAROPEN expr PARCLOSE #parens
 | 
					    : PAROPEN expr PARCLOSE #parens
 | 
				
			||||||
    | BRAOPEN expr BRACLOSE #block
 | 
					    | BRAOPEN expr BRACLOSE #block
 | 
				
			||||||
    | IN PAROPEN variable (LISTDELIM variable)* PARCLOSE #read
 | 
					    | IN PAROPEN variable (LISTDELIM variable)* PARCLOSE #read
 | 
				
			||||||
    | OUT PAROPEN expr (LISTDELIM expr)* PARCLOSE #write
 | 
					    | OUT PAROPEN expr (LISTDELIM expr)* PARCLOSE #write
 | 
				
			||||||
    | IFOPEN cond=expr IFTRUE onTrue=expr (IFFALSE onFalse=expr)? IFCLOSE #if
 | 
					    | IFOPEN cond=expr IFTRUE onTrue=expr (IFFALSE onFalse=expr)? IFCLOSE #if
 | 
				
			||||||
    | WHILEOPEN cond=expr WHILETRUE onTrue=expr WHILECLOSE #while
 | 
					    | WHILEOPEN cond=expr WHILETRUE onTrue=expr WHILECLOSE #while
 | 
				
			||||||
    | op=(PLUS|MINUS|NOT) expr #prefix1
 | 
					    | op=(PLUS|MINUS|NOT) singleExpr #prefix1
 | 
				
			||||||
    | lhs=expr op=(MULTIPLY|DIVIDE|MODULO) rhs=expr #infix1
 | 
					    | lhs=singleExpr op=(MULTIPLY|DIVIDE|MODULO) rhs=singleExpr #infix1
 | 
				
			||||||
    | lhs=expr op=(PLUS|MINUS) rhs=expr #infix2
 | 
					    | lhs=singleExpr op=(PLUS|MINUS) rhs=singleExpr #infix2
 | 
				
			||||||
    | lhs=expr op=(LT|LEQ|GTE|GT|EQ|NEQ) rhs=expr #infix3
 | 
					    | lhs=singleExpr op=(LT|LEQ|GTE|GT|EQ|NEQ) rhs=singleExpr #infix3
 | 
				
			||||||
    | lhs=expr AND rhs=expr #infix4
 | 
					    | lhs=singleExpr AND rhs=singleExpr #infix4
 | 
				
			||||||
    | lhs=expr OR rhs=expr #infix5
 | 
					    | lhs=singleExpr OR rhs=singleExpr #infix5
 | 
				
			||||||
    | DECLARE type IDENTIFIER #declare
 | 
					    | DECLARE type IDENTIFIER #declare
 | 
				
			||||||
    | <assoc=right> variable ASSIGN expr #assign
 | 
					    | <assoc=right> variable ASSIGN singleExpr #assign
 | 
				
			||||||
    | expr (COMPOUND expr?)+ #compound
 | 
					 | 
				
			||||||
    | variable #var
 | 
					    | variable #var
 | 
				
			||||||
    | LITERAL10 #number
 | 
					    | LITERAL10 #number
 | 
				
			||||||
    | CHAR #char
 | 
					    | CHAR #char
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,6 +18,13 @@ public class BasicBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements
 | 
				
			||||||
	 * {@link #visitChildren} on {@code ctx}.</p>
 | 
						 * {@link #visitChildren} on {@code ctx}.</p>
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	@Override public T visitProgram(BasicParser.ProgramContext ctx) { return visitChildren(ctx); }
 | 
						@Override public T visitProgram(BasicParser.ProgramContext ctx) { return visitChildren(ctx); }
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * {@inheritDoc}
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * <p>The default implementation returns the result of calling
 | 
				
			||||||
 | 
						 * {@link #visitChildren} on {@code ctx}.</p>
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						@Override public T visitExpr(BasicParser.ExprContext ctx) { return visitChildren(ctx); }
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * {@inheritDoc}
 | 
						 * {@inheritDoc}
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
| 
						 | 
					@ -81,13 +88,6 @@ public class BasicBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements
 | 
				
			||||||
	 * {@link #visitChildren} on {@code ctx}.</p>
 | 
						 * {@link #visitChildren} on {@code ctx}.</p>
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	@Override public T visitWhile(BasicParser.WhileContext ctx) { return visitChildren(ctx); }
 | 
						@Override public T visitWhile(BasicParser.WhileContext ctx) { return visitChildren(ctx); }
 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * {@inheritDoc}
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * <p>The default implementation returns the result of calling
 | 
					 | 
				
			||||||
	 * {@link #visitChildren} on {@code ctx}.</p>
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	@Override public T visitCompound(BasicParser.CompoundContext ctx) { return visitChildren(ctx); }
 | 
					 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * {@inheritDoc}
 | 
						 * {@inheritDoc}
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| 
						 | 
					@ -16,135 +16,134 @@ public interface BasicVisitor<T> extends ParseTreeVisitor<T> {
 | 
				
			||||||
	 * @return the visitor result
 | 
						 * @return the visitor result
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	T visitProgram(BasicParser.ProgramContext ctx);
 | 
						T visitProgram(BasicParser.ProgramContext ctx);
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Visit a parse tree produced by {@link BasicParser#expr}.
 | 
				
			||||||
 | 
						 * @param ctx the parse tree
 | 
				
			||||||
 | 
						 * @return the visitor result
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						T visitExpr(BasicParser.ExprContext ctx);
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Visit a parse tree produced by the {@code parens}
 | 
						 * Visit a parse tree produced by the {@code parens}
 | 
				
			||||||
	 * labeled alternative in {@link BasicParser#expr}.
 | 
						 * labeled alternative in {@link BasicParser#singleExpr}.
 | 
				
			||||||
	 * @param ctx the parse tree
 | 
						 * @param ctx the parse tree
 | 
				
			||||||
	 * @return the visitor result
 | 
						 * @return the visitor result
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	T visitParens(BasicParser.ParensContext ctx);
 | 
						T visitParens(BasicParser.ParensContext ctx);
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Visit a parse tree produced by the {@code read}
 | 
						 * Visit a parse tree produced by the {@code read}
 | 
				
			||||||
	 * labeled alternative in {@link BasicParser#expr}.
 | 
						 * labeled alternative in {@link BasicParser#singleExpr}.
 | 
				
			||||||
	 * @param ctx the parse tree
 | 
						 * @param ctx the parse tree
 | 
				
			||||||
	 * @return the visitor result
 | 
						 * @return the visitor result
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	T visitRead(BasicParser.ReadContext ctx);
 | 
						T visitRead(BasicParser.ReadContext ctx);
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Visit a parse tree produced by the {@code declare}
 | 
						 * Visit a parse tree produced by the {@code declare}
 | 
				
			||||||
	 * labeled alternative in {@link BasicParser#expr}.
 | 
						 * labeled alternative in {@link BasicParser#singleExpr}.
 | 
				
			||||||
	 * @param ctx the parse tree
 | 
						 * @param ctx the parse tree
 | 
				
			||||||
	 * @return the visitor result
 | 
						 * @return the visitor result
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	T visitDeclare(BasicParser.DeclareContext ctx);
 | 
						T visitDeclare(BasicParser.DeclareContext ctx);
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Visit a parse tree produced by the {@code bool}
 | 
						 * Visit a parse tree produced by the {@code bool}
 | 
				
			||||||
	 * labeled alternative in {@link BasicParser#expr}.
 | 
						 * labeled alternative in {@link BasicParser#singleExpr}.
 | 
				
			||||||
	 * @param ctx the parse tree
 | 
						 * @param ctx the parse tree
 | 
				
			||||||
	 * @return the visitor result
 | 
						 * @return the visitor result
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	T visitBool(BasicParser.BoolContext ctx);
 | 
						T visitBool(BasicParser.BoolContext ctx);
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Visit a parse tree produced by the {@code var}
 | 
						 * Visit a parse tree produced by the {@code var}
 | 
				
			||||||
	 * labeled alternative in {@link BasicParser#expr}.
 | 
						 * labeled alternative in {@link BasicParser#singleExpr}.
 | 
				
			||||||
	 * @param ctx the parse tree
 | 
						 * @param ctx the parse tree
 | 
				
			||||||
	 * @return the visitor result
 | 
						 * @return the visitor result
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	T visitVar(BasicParser.VarContext ctx);
 | 
						T visitVar(BasicParser.VarContext ctx);
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Visit a parse tree produced by the {@code infix2}
 | 
						 * Visit a parse tree produced by the {@code infix2}
 | 
				
			||||||
	 * labeled alternative in {@link BasicParser#expr}.
 | 
						 * labeled alternative in {@link BasicParser#singleExpr}.
 | 
				
			||||||
	 * @param ctx the parse tree
 | 
						 * @param ctx the parse tree
 | 
				
			||||||
	 * @return the visitor result
 | 
						 * @return the visitor result
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	T visitInfix2(BasicParser.Infix2Context ctx);
 | 
						T visitInfix2(BasicParser.Infix2Context ctx);
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Visit a parse tree produced by the {@code infix3}
 | 
						 * Visit a parse tree produced by the {@code infix3}
 | 
				
			||||||
	 * labeled alternative in {@link BasicParser#expr}.
 | 
						 * labeled alternative in {@link BasicParser#singleExpr}.
 | 
				
			||||||
	 * @param ctx the parse tree
 | 
						 * @param ctx the parse tree
 | 
				
			||||||
	 * @return the visitor result
 | 
						 * @return the visitor result
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	T visitInfix3(BasicParser.Infix3Context ctx);
 | 
						T visitInfix3(BasicParser.Infix3Context ctx);
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Visit a parse tree produced by the {@code infix1}
 | 
						 * Visit a parse tree produced by the {@code infix1}
 | 
				
			||||||
	 * labeled alternative in {@link BasicParser#expr}.
 | 
						 * labeled alternative in {@link BasicParser#singleExpr}.
 | 
				
			||||||
	 * @param ctx the parse tree
 | 
						 * @param ctx the parse tree
 | 
				
			||||||
	 * @return the visitor result
 | 
						 * @return the visitor result
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	T visitInfix1(BasicParser.Infix1Context ctx);
 | 
						T visitInfix1(BasicParser.Infix1Context ctx);
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Visit a parse tree produced by the {@code while}
 | 
						 * Visit a parse tree produced by the {@code while}
 | 
				
			||||||
	 * labeled alternative in {@link BasicParser#expr}.
 | 
						 * labeled alternative in {@link BasicParser#singleExpr}.
 | 
				
			||||||
	 * @param ctx the parse tree
 | 
						 * @param ctx the parse tree
 | 
				
			||||||
	 * @return the visitor result
 | 
						 * @return the visitor result
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	T visitWhile(BasicParser.WhileContext ctx);
 | 
						T visitWhile(BasicParser.WhileContext ctx);
 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Visit a parse tree produced by the {@code compound}
 | 
					 | 
				
			||||||
	 * labeled alternative in {@link BasicParser#expr}.
 | 
					 | 
				
			||||||
	 * @param ctx the parse tree
 | 
					 | 
				
			||||||
	 * @return the visitor result
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	T visitCompound(BasicParser.CompoundContext ctx);
 | 
					 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Visit a parse tree produced by the {@code infix4}
 | 
						 * Visit a parse tree produced by the {@code infix4}
 | 
				
			||||||
	 * labeled alternative in {@link BasicParser#expr}.
 | 
						 * labeled alternative in {@link BasicParser#singleExpr}.
 | 
				
			||||||
	 * @param ctx the parse tree
 | 
						 * @param ctx the parse tree
 | 
				
			||||||
	 * @return the visitor result
 | 
						 * @return the visitor result
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	T visitInfix4(BasicParser.Infix4Context ctx);
 | 
						T visitInfix4(BasicParser.Infix4Context ctx);
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Visit a parse tree produced by the {@code infix5}
 | 
						 * Visit a parse tree produced by the {@code infix5}
 | 
				
			||||||
	 * labeled alternative in {@link BasicParser#expr}.
 | 
						 * labeled alternative in {@link BasicParser#singleExpr}.
 | 
				
			||||||
	 * @param ctx the parse tree
 | 
						 * @param ctx the parse tree
 | 
				
			||||||
	 * @return the visitor result
 | 
						 * @return the visitor result
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	T visitInfix5(BasicParser.Infix5Context ctx);
 | 
						T visitInfix5(BasicParser.Infix5Context ctx);
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Visit a parse tree produced by the {@code number}
 | 
						 * Visit a parse tree produced by the {@code number}
 | 
				
			||||||
	 * labeled alternative in {@link BasicParser#expr}.
 | 
						 * labeled alternative in {@link BasicParser#singleExpr}.
 | 
				
			||||||
	 * @param ctx the parse tree
 | 
						 * @param ctx the parse tree
 | 
				
			||||||
	 * @return the visitor result
 | 
						 * @return the visitor result
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	T visitNumber(BasicParser.NumberContext ctx);
 | 
						T visitNumber(BasicParser.NumberContext ctx);
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Visit a parse tree produced by the {@code char}
 | 
						 * Visit a parse tree produced by the {@code char}
 | 
				
			||||||
	 * labeled alternative in {@link BasicParser#expr}.
 | 
						 * labeled alternative in {@link BasicParser#singleExpr}.
 | 
				
			||||||
	 * @param ctx the parse tree
 | 
						 * @param ctx the parse tree
 | 
				
			||||||
	 * @return the visitor result
 | 
						 * @return the visitor result
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	T visitChar(BasicParser.CharContext ctx);
 | 
						T visitChar(BasicParser.CharContext ctx);
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Visit a parse tree produced by the {@code block}
 | 
						 * Visit a parse tree produced by the {@code block}
 | 
				
			||||||
	 * labeled alternative in {@link BasicParser#expr}.
 | 
						 * labeled alternative in {@link BasicParser#singleExpr}.
 | 
				
			||||||
	 * @param ctx the parse tree
 | 
						 * @param ctx the parse tree
 | 
				
			||||||
	 * @return the visitor result
 | 
						 * @return the visitor result
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	T visitBlock(BasicParser.BlockContext ctx);
 | 
						T visitBlock(BasicParser.BlockContext ctx);
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Visit a parse tree produced by the {@code write}
 | 
						 * Visit a parse tree produced by the {@code write}
 | 
				
			||||||
	 * labeled alternative in {@link BasicParser#expr}.
 | 
						 * labeled alternative in {@link BasicParser#singleExpr}.
 | 
				
			||||||
	 * @param ctx the parse tree
 | 
						 * @param ctx the parse tree
 | 
				
			||||||
	 * @return the visitor result
 | 
						 * @return the visitor result
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	T visitWrite(BasicParser.WriteContext ctx);
 | 
						T visitWrite(BasicParser.WriteContext ctx);
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Visit a parse tree produced by the {@code if}
 | 
						 * Visit a parse tree produced by the {@code if}
 | 
				
			||||||
	 * labeled alternative in {@link BasicParser#expr}.
 | 
						 * labeled alternative in {@link BasicParser#singleExpr}.
 | 
				
			||||||
	 * @param ctx the parse tree
 | 
						 * @param ctx the parse tree
 | 
				
			||||||
	 * @return the visitor result
 | 
						 * @return the visitor result
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	T visitIf(BasicParser.IfContext ctx);
 | 
						T visitIf(BasicParser.IfContext ctx);
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Visit a parse tree produced by the {@code prefix1}
 | 
						 * Visit a parse tree produced by the {@code prefix1}
 | 
				
			||||||
	 * labeled alternative in {@link BasicParser#expr}.
 | 
						 * labeled alternative in {@link BasicParser#singleExpr}.
 | 
				
			||||||
	 * @param ctx the parse tree
 | 
						 * @param ctx the parse tree
 | 
				
			||||||
	 * @return the visitor result
 | 
						 * @return the visitor result
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	T visitPrefix1(BasicParser.Prefix1Context ctx);
 | 
						T visitPrefix1(BasicParser.Prefix1Context ctx);
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Visit a parse tree produced by the {@code assign}
 | 
						 * Visit a parse tree produced by the {@code assign}
 | 
				
			||||||
	 * labeled alternative in {@link BasicParser#expr}.
 | 
						 * labeled alternative in {@link BasicParser#singleExpr}.
 | 
				
			||||||
	 * @param ctx the parse tree
 | 
						 * @param ctx the parse tree
 | 
				
			||||||
	 * @return the visitor result
 | 
						 * @return the visitor result
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue