MESSAGE
DATE | 2016-04-09 |
FROM | Christopher League
|
SUBJECT | Re: [Hangout-NYLXS] Antlr visitor Programming - kicking it around
|
From hangout-bounces-at-nylxs.com Sat Apr 9 11:07:38 2016 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: from www.mrbrklyn.com (www.mrbrklyn.com [96.57.23.82]) by mrbrklyn.com (Postfix) with ESMTP id 2D557161224; Sat, 9 Apr 2016 11:07:36 -0400 (EDT) X-Original-To: hangout-at-www.mrbrklyn.com Delivered-To: hangout-at-www.mrbrklyn.com Received: by mrbrklyn.com (Postfix, from userid 1000) id 288EE161914; Sat, 9 Apr 2016 11:07:26 -0400 (EDT) Resent-From: Ruben Safir Resent-Date: Sat, 9 Apr 2016 11:07:25 -0400 Resent-Message-ID: <20160409150725.GA3493-at-www.mrbrklyn.com> Resent-To: hangout-at-mrbrklyn.com X-Original-To: ruben-at-mrbrklyn.com Delivered-To: ruben-at-mrbrklyn.com Received: from B-EXH-EDGE1.liunet.edu (b-edge1.smtp.liu.edu [148.4.248.206]) by mrbrklyn.com (Postfix) with ESMTP id 15155161914 for ; Sat, 9 Apr 2016 09:19:16 -0400 (EDT) Received: from B-EXH-3.liunet.edu (148.4.250.212) by B-EXH-EDGE1.liunet.edu (148.4.248.206) with Microsoft SMTP Server (TLS) id 14.3.210.2; Sat, 9 Apr 2016 09:19:01 -0400 Received: from localhost (96.250.202.133) by B-EXH-3.liunet.edu (148.4.250.212) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Sat, 9 Apr 2016 09:19:14 -0400 From: Christopher League To: Ruben Safir , Hangout In-Reply-To: <5708706F.5040305-at-mrbrklyn.com> References: <5708706F.5040305-at-mrbrklyn.com> User-Agent: Notmuch/0.21 (http://notmuchmail.org) Emacs/24.5.1 (x86_64-unknown-linux-gnu) Date: Sat, 9 Apr 2016 09:19:13 -0400 Message-ID: <87lh4m7wdq.fsf-at-lydrik.home.lan> MIME-Version: 1.0 X-Originating-IP: [96.250.202.133] X-ClientProxiedBy: U-EXH-CAS.liunet.edu (148.4.184.26) To B-EXH-3.liunet.edu (148.4.250.212) X-UID: 18748 X-Content-Filtered-By: Mailman/MimeDel 2.1.17 Subject: Re: [Hangout-NYLXS] Antlr visitor Programming - kicking it around X-BeenThere: hangout-at-nylxs.com X-Mailman-Version: 2.1.17 Precedence: list Reply-To: NYLXS Discussions List List-Id: NYLXS Discussions List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============0359403622==" Errors-To: hangout-bounces-at-nylxs.com Sender: "hangout"
--===============0359403622== Content-Type: multipart/alternative; boundary="=-=-="
--=-=-= Content-Type: text/plain
> So I'm only visiting visitAssignID and visitQuantity and > visitVariables?
Not even visitQuantity, I think. The purpose of `CollectVarsVisitor` was to "traverse a parse tree for the calculator language and just keep track of the set of identifiers that are being referenced (assigned or retrieved) in the program."
If we look at the grammar:
stmt : ID '=' expr #assignID | 'print' expr #print ;
expr : '-' expr #negative | expr ('*' | '/') expr #products_quotents | expr ('+'|'-') expr #sums | '(' expr ')' #parans |NUM #quantity |ID #variables ;
The only place that a variable is assigned is in `#assignID` and the only place a variable is retrieved is in `#variables`. So those are the only two visit methods we'd need to fulfill the purpose of `CollectVarsVisitor`.
The `AssignIDContext` and `VariablesContext` will each have a `ctx.ID()` because ID appears in both of those rules. And because it appears exactly once in each, the method returns just a single `TerminalNode`, rather than a list of them. The other contexts (tree nodes) don't have any ID, so there is no `ctx.ID()` method in those.
CL
Ruben Safir writes:
> So kicking this around, forget that this HW is now a month old... > > I did this which fails, and I know why...I think > > > Note that it fails on contex objects that have no ID() > > > import org.antlr.v4.runtime.ANTLRInputStream; > import org.antlr.v4.runtime.CommonTokenStream; > import org.antlr.v4.runtime.tree.ParseTree; > import org.antlr.v4.runtime.tree.TerminalNode; > import org.antlr.v4.runtime.*; > import org.antlr.v4.runtime.tree.*; > import java.util.HashSet; > > public class CollectVarsVisitor extends CalcBaseVisitor { > HashSet vars = new HashSet(); > > //STMT > -at-Override > public Void visitAssignID(CalcParser.AssignIDContext ctx) { > TerminalNode id = ctx.ID(); > if(id != null) { > System.out.println(id.getText()); > vars.add(id.getText()); > } > return super.visitAssignID(ctx); > } > > -at-Override > public Void visitPrint(CalcParser.PrintContext ctx) { > TerminalNode id = ctx.ID(); > if(id != null) { > System.out.println(id.getText()); > vars.add(id.getText()); > } > return super.visitPrint(ctx); > } > > //EXPR > > -at-Override > public Void visitNegative(CalcParser.NegativeContext ctx) { > TerminalNode id = ctx.ID(); > if(id != null) { > System.out.println("expresion: " + id.getText()); > vars.add(id.getText()); > } > return super.visitNegative(ctx); > } > > > -at-Override > public Void visitProducts_quotents(CalcParser.Products_quotentsContext ctx) { > TerminalNode id = ctx.ID(); > if(id != null) { > System.out.println("expresion: " + id.getText()); > vars.add(id.getText()); > } > return super.visitProducts_quotents(ctx); > } > > -at-Override > public Void visitSums(CalcParser.SumsContext ctx) { > TerminalNode id = ctx.ID(); > if(id != null) { > System.out.println("expresion: " + id.getText()); > vars.add(id.getText()); > } > return super.visitSums(ctx); > } > > -at-Override > public Void visitParans(CalcParser.ParansContext ctx) { > TerminalNode id = ctx.ID(); > if(id != null) { > System.out.println("expresion: " + id.getText()); > vars.add(id.getText()); > } > return super.visitParans(ctx); > } > > -at-Override > public Void visitQuantity(CalcParser.QuantityContext ctx) { > TerminalNode id = ctx.ID(); > if(id != null) { > System.out.println("expresion: " + id.getText()); > vars.add(id.getText()); > } > return super.visitQuantity(ctx); > } > > -at-Override > public Void visitVariables(CalcParser.VariablesContext ctx) { > TerminalNode id = ctx.ID(); > if(id != null) { > System.out.println("expresion: " + id.getText()); > vars.add(id.getText()); > } > return super.visitVariables(ctx); > } > } > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > [ruben-at-manjaro calculator]$ javac Main.java > ./CollectVarsVisitor.java:25: error: cannot find symbol > TerminalNode id = ctx.ID(); > ^ > symbol: method ID() > location: variable ctx of type PrintContext > ./CollectVarsVisitor.java:37: error: cannot find symbol > TerminalNode id = ctx.ID(); > ^ > symbol: method ID() > location: variable ctx of type NegativeContext > ./CollectVarsVisitor.java:48: error: cannot find symbol > TerminalNode id = ctx.ID(); > ^ > symbol: method ID() > location: variable ctx of type Products_quotentsContext > ./CollectVarsVisitor.java:58: error: cannot find symbol > TerminalNode id = ctx.ID(); > ^ > symbol: method ID() > location: variable ctx of type SumsContext > ./CollectVarsVisitor.java:68: error: cannot find symbol > TerminalNode id = ctx.ID(); > ^ > symbol: method ID() > location: variable ctx of type ParansContext > ./CollectVarsVisitor.java:78: error: cannot find symbol > TerminalNode id = ctx.ID(); > ^ > symbol: method ID() > location: variable ctx of type QuantityContext > Note: Some input files use or override a deprecated API. > Note: Recompile with -Xlint:deprecation for details. > 6 errors > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > cat Calc.g4 > grammar Calc; > > prog : (stmt ';')* > ; > > stmt : ID '=' expr #assignID > | 'print' expr #print > ; > > expr : '-' expr #negative > | expr ('*' | '/') expr #products_quotents > | expr ('+'|'-') expr #sums > | '(' expr ')' #parans > |NUM #quantity > |ID #variables > ; > > NUM : [0-9]+ ('.' [0-9]+)? > ; > ID :[a-zA-Z]+ > ; > WS :(' '|'\n'|'\t'|'\r')+ ->skip > ; > > So I'm only visiting visitAssignID and visitQuantity and visitVariables? > > Ruben > > -- > So many immigrant groups have swept through our town > that Brooklyn, like Atlantis, reaches mythological > proportions in the mind of the world - RI Safir 1998 > http://www.mrbrklyn.com > > DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002 > http://www.nylxs.com - Leadership Development in Free Software > http://www2.mrbrklyn.com/resources - Unpublished Archive > http://www.coinhangout.com - coins! > http://www.brooklyn-living.com > > Being so tracked is for FARM ANIMALS and and extermination camps, > but incompatible with living as a free human being. -RI Safir 2013
--=-=-= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8"
So I'm only visiting visitAssignID and visitQuantity and visitVariables?
Not even visitQuantity, I think. The purpose of CollectVarsVisitor was to "traverse a parse tree for the calculator language and just keep track of the set of identifiers that are being referenced (assigned or retrieved) in the program."
If we look at the grammar: stmt : ID '=' expr #assignID | 'print' expr #print ;
expr : '-' expr #negative | expr ('*' | '/') expr #products_quotents | expr ('+'|'-') expr #sums | '(' expr ')' #parans |NUM #quantity |ID #variables ;
The only place that a variable is assigned is in #assignID and the only place a variable is retrieved is in #variables. So those are the only two visit methods we'd need to fulfill the purpose of CollectVarsVisitor.
The AssignIDContext and VariablesContext will each have a ctx.ID() because ID appears in both of those rules. And because it appears exactly once in each, the method returns just a single TerminalNode, rather than a list of them. The other contexts (tree nodes) don't have any ID, so there is no ctx.ID() method in those.
CL
Ruben Safir [1]ruben-at-mrbrklyn.com writes:
So kicking this around, forget that this HW is now a month old...
I did this which fails, and I know why...I think
Note that it fails on contex objects that have no ID()
import org.antlr.v4.runtime.ANTLRInputStream; import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.tree.ParseTree; import org.antlr.v4.runtime.tree.TerminalNode; import org.antlr.v4.runtime.; import org.antlr.v4.runtime.tree.; import java.util.HashSet;
public class CollectVarsVisitor extends CalcBaseVisitor { HashSet vars = new HashSet();
//STMT -at-Override public Void visitAssignID(CalcParser.AssignIDContext ctx) { TerminalNode id = ctx.ID(); if(id != null) { System.out.println(id.getText()); vars.add(id.getText()); } return super.visitAssignID(ctx); } -at-Override public Void visitPrint(CalcParser.PrintContext ctx) { TerminalNode id = ctx.ID(); if(id != null) { System.out.println(id.getText()); vars.add(id.getText()); } return super.visitPrint(ctx); }
//EXPR -at-Override public Void visitNegative(CalcParser.NegativeContext ctx) { TerminalNode id = ctx.ID(); if(id != null) { System.out.println("expresion: " + id.getText()); vars.add(id.getText()); } return super.visitNegative(ctx); }
-at-Override public Void visitProducts_quotents(CalcParser.Products_quotentsContext ctx) { TerminalNode id = ctx.ID(); if(id != null) { System.out.println("expresion: " + id.getText()); vars.add(id.getText()); } return super.visitProducts_quotents(ctx); }
-at-Override public Void visitSums(CalcParser.SumsContext ctx) { TerminalNode id = ctx.ID(); if(id != null) { System.out.println("expresion: " + id.getText()); vars.add(id.getText()); } return super.visitSums(ctx); }
-at-Override public Void visitParans(CalcParser.ParansContext ctx) { TerminalNode id = ctx.ID(); if(id != null) { System.out.println("expresion: " + id.getText()); vars.add(id.getText()); } return super.visitParans(ctx); }
-at-Override public Void visitQuantity(CalcParser.QuantityContext ctx) { TerminalNode id = ctx.ID(); if(id != null) { System.out.println("expresion: " + id.getText()); vars.add(id.getText()); } return super.visitQuantity(ctx); }
-at-Override public Void visitVariables(CalcParser.VariablesContext ctx) { TerminalNode id = ctx.ID(); if(id != null) { System.out.println("expresion: " + id.getText()); vars.add(id.getText()); } return super.visitVariables(ctx); }
}
[ruben-at-manjaro calculator]$ javac Main.java ./CollectVarsVisitor.java:25: error: cannot find symbol TerminalNode id = ctx.ID(); ^ symbol: method ID() location: variable ctx of type PrintContext ./CollectVarsVisitor.java:37: error: cannot find symbol TerminalNode id = ctx.ID(); ^ symbol: method ID() location: variable ctx of type NegativeContext ./CollectVarsVisitor.java:48: error: cannot find symbol TerminalNode id = ctx.ID(); ^ symbol: method ID() location: variable ctx of type Products_quotentsContext ./CollectVarsVisitor.java:58: error: cannot find symbol TerminalNode id = ctx.ID(); ^ symbol: method ID() location: variable ctx of type SumsContext ./CollectVarsVisitor.java:68: error: cannot find symbol TerminalNode id = ctx.ID(); ^ symbol: method ID() location: variable ctx of type ParansContext ./CollectVarsVisitor.java:78: error: cannot find symbol TerminalNode id = ctx.ID(); ^ symbol: method ID() location: variable ctx of type QuantityContext Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. 6 errors
cat Calc.g4 grammar Calc;
prog : (stmt `;')* ;
stmt : ID `=' expr #assignID | `print' expr #print ;
expr : `-' expr #negative | expr ('*`|'/`) expr #products_quotents | expr ('+`|'-`) expr #sums |'(`expr')' #parans |NUM #quantity |ID #variables ;
NUM : [0-9]+ ('.`[0-9]+)? ; ID :[a-zA-Z]+ ; WS :(' `|'`|'`|'')+ ->skip ;
So I'm only visiting visitAssignID and visitQuantity and visitVariables?
Ruben
- So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998 http://www.mrbrklyn.com
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002 http://www.nylxs.com - Leadership Development in Free Software http://www2.mrbrklyn.com/resources - Unpublished Archive http://www.coinhangout.com - coins! http://www.brooklyn-living.com
Being so tracked is for FARM ANIMALS and and extermination camps, but incompatible with living as a free human being. -RI Safir 2013
References
1. mailto:ruben-at-mrbrklyn.com
--=-=-=--
--===============0359403622== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline
_______________________________________________ hangout mailing list hangout-at-nylxs.com http://www.nylxs.com/ --===============0359403622==--
--===============0359403622== Content-Type: multipart/alternative; boundary="=-=-="
--=-=-= Content-Type: text/plain
> So I'm only visiting visitAssignID and visitQuantity and > visitVariables?
Not even visitQuantity, I think. The purpose of `CollectVarsVisitor` was to "traverse a parse tree for the calculator language and just keep track of the set of identifiers that are being referenced (assigned or retrieved) in the program."
If we look at the grammar:
stmt : ID '=' expr #assignID | 'print' expr #print ;
expr : '-' expr #negative | expr ('*' | '/') expr #products_quotents | expr ('+'|'-') expr #sums | '(' expr ')' #parans |NUM #quantity |ID #variables ;
The only place that a variable is assigned is in `#assignID` and the only place a variable is retrieved is in `#variables`. So those are the only two visit methods we'd need to fulfill the purpose of `CollectVarsVisitor`.
The `AssignIDContext` and `VariablesContext` will each have a `ctx.ID()` because ID appears in both of those rules. And because it appears exactly once in each, the method returns just a single `TerminalNode`, rather than a list of them. The other contexts (tree nodes) don't have any ID, so there is no `ctx.ID()` method in those.
CL
Ruben Safir writes:
> So kicking this around, forget that this HW is now a month old... > > I did this which fails, and I know why...I think > > > Note that it fails on contex objects that have no ID() > > > import org.antlr.v4.runtime.ANTLRInputStream; > import org.antlr.v4.runtime.CommonTokenStream; > import org.antlr.v4.runtime.tree.ParseTree; > import org.antlr.v4.runtime.tree.TerminalNode; > import org.antlr.v4.runtime.*; > import org.antlr.v4.runtime.tree.*; > import java.util.HashSet; > > public class CollectVarsVisitor extends CalcBaseVisitor { > HashSet vars = new HashSet(); > > //STMT > -at-Override > public Void visitAssignID(CalcParser.AssignIDContext ctx) { > TerminalNode id = ctx.ID(); > if(id != null) { > System.out.println(id.getText()); > vars.add(id.getText()); > } > return super.visitAssignID(ctx); > } > > -at-Override > public Void visitPrint(CalcParser.PrintContext ctx) { > TerminalNode id = ctx.ID(); > if(id != null) { > System.out.println(id.getText()); > vars.add(id.getText()); > } > return super.visitPrint(ctx); > } > > //EXPR > > -at-Override > public Void visitNegative(CalcParser.NegativeContext ctx) { > TerminalNode id = ctx.ID(); > if(id != null) { > System.out.println("expresion: " + id.getText()); > vars.add(id.getText()); > } > return super.visitNegative(ctx); > } > > > -at-Override > public Void visitProducts_quotents(CalcParser.Products_quotentsContext ctx) { > TerminalNode id = ctx.ID(); > if(id != null) { > System.out.println("expresion: " + id.getText()); > vars.add(id.getText()); > } > return super.visitProducts_quotents(ctx); > } > > -at-Override > public Void visitSums(CalcParser.SumsContext ctx) { > TerminalNode id = ctx.ID(); > if(id != null) { > System.out.println("expresion: " + id.getText()); > vars.add(id.getText()); > } > return super.visitSums(ctx); > } > > -at-Override > public Void visitParans(CalcParser.ParansContext ctx) { > TerminalNode id = ctx.ID(); > if(id != null) { > System.out.println("expresion: " + id.getText()); > vars.add(id.getText()); > } > return super.visitParans(ctx); > } > > -at-Override > public Void visitQuantity(CalcParser.QuantityContext ctx) { > TerminalNode id = ctx.ID(); > if(id != null) { > System.out.println("expresion: " + id.getText()); > vars.add(id.getText()); > } > return super.visitQuantity(ctx); > } > > -at-Override > public Void visitVariables(CalcParser.VariablesContext ctx) { > TerminalNode id = ctx.ID(); > if(id != null) { > System.out.println("expresion: " + id.getText()); > vars.add(id.getText()); > } > return super.visitVariables(ctx); > } > } > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > [ruben-at-manjaro calculator]$ javac Main.java > ./CollectVarsVisitor.java:25: error: cannot find symbol > TerminalNode id = ctx.ID(); > ^ > symbol: method ID() > location: variable ctx of type PrintContext > ./CollectVarsVisitor.java:37: error: cannot find symbol > TerminalNode id = ctx.ID(); > ^ > symbol: method ID() > location: variable ctx of type NegativeContext > ./CollectVarsVisitor.java:48: error: cannot find symbol > TerminalNode id = ctx.ID(); > ^ > symbol: method ID() > location: variable ctx of type Products_quotentsContext > ./CollectVarsVisitor.java:58: error: cannot find symbol > TerminalNode id = ctx.ID(); > ^ > symbol: method ID() > location: variable ctx of type SumsContext > ./CollectVarsVisitor.java:68: error: cannot find symbol > TerminalNode id = ctx.ID(); > ^ > symbol: method ID() > location: variable ctx of type ParansContext > ./CollectVarsVisitor.java:78: error: cannot find symbol > TerminalNode id = ctx.ID(); > ^ > symbol: method ID() > location: variable ctx of type QuantityContext > Note: Some input files use or override a deprecated API. > Note: Recompile with -Xlint:deprecation for details. > 6 errors > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > cat Calc.g4 > grammar Calc; > > prog : (stmt ';')* > ; > > stmt : ID '=' expr #assignID > | 'print' expr #print > ; > > expr : '-' expr #negative > | expr ('*' | '/') expr #products_quotents > | expr ('+'|'-') expr #sums > | '(' expr ')' #parans > |NUM #quantity > |ID #variables > ; > > NUM : [0-9]+ ('.' [0-9]+)? > ; > ID :[a-zA-Z]+ > ; > WS :(' '|'\n'|'\t'|'\r')+ ->skip > ; > > So I'm only visiting visitAssignID and visitQuantity and visitVariables? > > Ruben > > -- > So many immigrant groups have swept through our town > that Brooklyn, like Atlantis, reaches mythological > proportions in the mind of the world - RI Safir 1998 > http://www.mrbrklyn.com > > DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002 > http://www.nylxs.com - Leadership Development in Free Software > http://www2.mrbrklyn.com/resources - Unpublished Archive > http://www.coinhangout.com - coins! > http://www.brooklyn-living.com > > Being so tracked is for FARM ANIMALS and and extermination camps, > but incompatible with living as a free human being. -RI Safir 2013
--=-=-= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8"
So I'm only visiting visitAssignID and visitQuantity and visitVariables?
Not even visitQuantity, I think. The purpose of CollectVarsVisitor was to "traverse a parse tree for the calculator language and just keep track of the set of identifiers that are being referenced (assigned or retrieved) in the program."
If we look at the grammar: stmt : ID '=' expr #assignID | 'print' expr #print ;
expr : '-' expr #negative | expr ('*' | '/') expr #products_quotents | expr ('+'|'-') expr #sums | '(' expr ')' #parans |NUM #quantity |ID #variables ;
The only place that a variable is assigned is in #assignID and the only place a variable is retrieved is in #variables. So those are the only two visit methods we'd need to fulfill the purpose of CollectVarsVisitor.
The AssignIDContext and VariablesContext will each have a ctx.ID() because ID appears in both of those rules. And because it appears exactly once in each, the method returns just a single TerminalNode, rather than a list of them. The other contexts (tree nodes) don't have any ID, so there is no ctx.ID() method in those.
CL
Ruben Safir [1]ruben-at-mrbrklyn.com writes:
So kicking this around, forget that this HW is now a month old...
I did this which fails, and I know why...I think
Note that it fails on contex objects that have no ID()
import org.antlr.v4.runtime.ANTLRInputStream; import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.tree.ParseTree; import org.antlr.v4.runtime.tree.TerminalNode; import org.antlr.v4.runtime.; import org.antlr.v4.runtime.tree.; import java.util.HashSet;
public class CollectVarsVisitor extends CalcBaseVisitor { HashSet vars = new HashSet();
//STMT -at-Override public Void visitAssignID(CalcParser.AssignIDContext ctx) { TerminalNode id = ctx.ID(); if(id != null) { System.out.println(id.getText()); vars.add(id.getText()); } return super.visitAssignID(ctx); } -at-Override public Void visitPrint(CalcParser.PrintContext ctx) { TerminalNode id = ctx.ID(); if(id != null) { System.out.println(id.getText()); vars.add(id.getText()); } return super.visitPrint(ctx); }
//EXPR -at-Override public Void visitNegative(CalcParser.NegativeContext ctx) { TerminalNode id = ctx.ID(); if(id != null) { System.out.println("expresion: " + id.getText()); vars.add(id.getText()); } return super.visitNegative(ctx); }
-at-Override public Void visitProducts_quotents(CalcParser.Products_quotentsContext ctx) { TerminalNode id = ctx.ID(); if(id != null) { System.out.println("expresion: " + id.getText()); vars.add(id.getText()); } return super.visitProducts_quotents(ctx); }
-at-Override public Void visitSums(CalcParser.SumsContext ctx) { TerminalNode id = ctx.ID(); if(id != null) { System.out.println("expresion: " + id.getText()); vars.add(id.getText()); } return super.visitSums(ctx); }
-at-Override public Void visitParans(CalcParser.ParansContext ctx) { TerminalNode id = ctx.ID(); if(id != null) { System.out.println("expresion: " + id.getText()); vars.add(id.getText()); } return super.visitParans(ctx); }
-at-Override public Void visitQuantity(CalcParser.QuantityContext ctx) { TerminalNode id = ctx.ID(); if(id != null) { System.out.println("expresion: " + id.getText()); vars.add(id.getText()); } return super.visitQuantity(ctx); }
-at-Override public Void visitVariables(CalcParser.VariablesContext ctx) { TerminalNode id = ctx.ID(); if(id != null) { System.out.println("expresion: " + id.getText()); vars.add(id.getText()); } return super.visitVariables(ctx); }
}
[ruben-at-manjaro calculator]$ javac Main.java ./CollectVarsVisitor.java:25: error: cannot find symbol TerminalNode id = ctx.ID(); ^ symbol: method ID() location: variable ctx of type PrintContext ./CollectVarsVisitor.java:37: error: cannot find symbol TerminalNode id = ctx.ID(); ^ symbol: method ID() location: variable ctx of type NegativeContext ./CollectVarsVisitor.java:48: error: cannot find symbol TerminalNode id = ctx.ID(); ^ symbol: method ID() location: variable ctx of type Products_quotentsContext ./CollectVarsVisitor.java:58: error: cannot find symbol TerminalNode id = ctx.ID(); ^ symbol: method ID() location: variable ctx of type SumsContext ./CollectVarsVisitor.java:68: error: cannot find symbol TerminalNode id = ctx.ID(); ^ symbol: method ID() location: variable ctx of type ParansContext ./CollectVarsVisitor.java:78: error: cannot find symbol TerminalNode id = ctx.ID(); ^ symbol: method ID() location: variable ctx of type QuantityContext Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. 6 errors
cat Calc.g4 grammar Calc;
prog : (stmt `;')* ;
stmt : ID `=' expr #assignID | `print' expr #print ;
expr : `-' expr #negative | expr ('*`|'/`) expr #products_quotents | expr ('+`|'-`) expr #sums |'(`expr')' #parans |NUM #quantity |ID #variables ;
NUM : [0-9]+ ('.`[0-9]+)? ; ID :[a-zA-Z]+ ; WS :(' `|'`|'`|'')+ ->skip ;
So I'm only visiting visitAssignID and visitQuantity and visitVariables?
Ruben
- So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998 http://www.mrbrklyn.com
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002 http://www.nylxs.com - Leadership Development in Free Software http://www2.mrbrklyn.com/resources - Unpublished Archive http://www.coinhangout.com - coins! http://www.brooklyn-living.com
Being so tracked is for FARM ANIMALS and and extermination camps, but incompatible with living as a free human being. -RI Safir 2013
References
1. mailto:ruben-at-mrbrklyn.com
--=-=-=--
--===============0359403622== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline
_______________________________________________ hangout mailing list hangout-at-nylxs.com http://www.nylxs.com/ --===============0359403622==--
|
|