MESSAGE
DATE | 2016-03-14 |
FROM | Christopher League
|
SUBJECT | Re: [Learn] CTX object
|
From learn-bounces-at-nylxs.com Mon Mar 14 20:52:02 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 61CB3163D4B; Mon, 14 Mar 2016 20:52:02 -0400 (EDT) X-Original-To: learn-at-nylxs.com Delivered-To: learn-at-nylxs.com Received: from B-EXH-EDGE1.liunet.edu (b-edge1.smtp.liu.edu [148.4.248.206]) by mrbrklyn.com (Postfix) with ESMTP id 9DCF4163D43; Mon, 14 Mar 2016 19:39:57 -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; Mon, 14 Mar 2016 19:39:53 -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.1130.7; Mon, 14 Mar 2016 19:39:56 -0400 From: Christopher League To: Ruben.Safir , , In-Reply-To: <56E74339.6080100-at-my.liu.edu> Message-ID: <87wpp43a5q.fsf-at-lydrik.home.lan> References: <56E74339.6080100-at-my.liu.edu> User-Agent: Notmuch/0.21 (http://notmuchmail.org) Emacs/24.5.1 (x86_64-unknown-linux-gnu) Date: Mon, 14 Mar 2016 19:39:52 -0400 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-Mailman-Approved-At: Mon, 14 Mar 2016 20:51:46 -0400 Subject: Re: [Learn] CTX object X-BeenThere: learn-at-nylxs.com X-Mailman-Version: 2.1.17 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============1958295665==" Errors-To: learn-bounces-at-nylxs.com Sender: "Learn"
--===============1958295665== Content-Type: multipart/signed; boundary="===-=-="; micalg=pgp-sha256; protocol="application/pgp-signature"
--===-=-= Content-Type: multipart/mixed; boundary="=-=-="
--=-=-= Content-Type: multipart/alternative; boundary="==-=-="
--==-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable
The parameter `ctx` (aka context) refers to a node in the parse tree. So they are instantiated within the Parser class generated by ANTLR. As it parses the input stream, it generates these nodes.
Because it's using a *heterogeneous* tree representation, it actually can refer to a variety of different classes, in this case `ProgContext` to represent programs (the `prog` non-terminal), `StmtContext` to represent statements, and `ExprContext` for expressions. The exact set of context classes will depend on your grammar and the use of the "hash tags" described in "Distinguishing rule alternatives."
They are all subclasses of `ParserRuleContext` (in the ANTLR library), which is in turn a subclass of `ParseTree`.
CL
"Ruben.Safir" writes:
> can anyone tell me where this ctx object is defined and when it is=20 > instantiated? > > > visitProg(ctx) top-level program > where ctx.stmt(0).getText() is "n=3D5" > and ctx.stmt(1).getText() is "print -3*(n+1)" > visitStmt(ctx) assignment statement > where ctx.ID().getText() is "n" > and ctx.expr().getText() is "5" > visitExpr(ctx) numeric literal > where ctx.NUM().getText() is "5" > visitStmt(ctx) print statementan > where ctx.ID() is null > and ctx.expr().getText() is "-3*(n+1)" > visitExpr(ctx) multiplication > where ctx.expr(0).getText() is "-3" > and ctx.expr(1).getText() is "(n+1)" > visitExpr(ctx) negation > where ctx.expr(0).getText() is "3" > visitExpr(ctx) numeric literal > where ctx.NUM().getText() is "3" > visitExpr(ctx) parentheses > where ctx.expr(0).getText() is "n+1" > visitExpr(ctx) addition > where ctx.expr(0).getText() is "n" > and ctx.expr(1).getText() is "1" > visitExpr(ctx) variable > where ctx.ID().getText() is "n" > visitExpr(ctx) numeric literal > where ctx.NUM().getText() is "1"
--==-=-= Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
1.0, user-scalable=3Dyes">
The parameter ctx (aka context) refers to a node in the par= se tree. So they are instantiated within the Parser class generated by ANTL= R. As it parses the input stream, it generates these nodes.
Because it=E2=80=99s using a heterogeneous tree representation,= it actually can refer to a variety of different classes, in this case e>ProgContext to represent programs (the prog non-termi= nal), StmtContext to represent statements, and ExprConte= xt for expressions. The exact set of context classes will depend on = your grammar and the use of the =E2=80=9Chash tags=E2=80=9D described in = =E2=80=9CDistinguishing rule alternatives.=E2=80=9D s.net/cs664s16/visitor.html#distinguishing-rule-alternatives" class=3D"uri"= >https://liucs.net/cs664s16/visitor.html#distinguishing-rule-alternatives= a>
They are all subclasses of ParserRuleContext (in the ANTLR = library), which is in turn a subclass of ParseTree .
CL
=E2=80=9CRuben.Safir=E2=80=9D = ruben.safir-at-my.liu.edu writes:
can anyone tell me where this ctx object is defined and when it is insta= ntiated?
visitProg(ctx) top-level program where ctx.stmt(0).getText() is "n=3D5" and ctx.stmt(1).getText() is "print -3*(n+1)" visitStmt(ctx) assignment statement where ctx.ID().getText() is "n" and ctx.expr().getText() is "5" visitExpr(ctx) numeric literal where ctx.NUM().getText() is "5" visitStmt(ctx) print statementan where ctx.ID() is null and ctx.expr().getText() is "-3*(n+1)" visitExpr(ctx) multiplication where ctx.expr(0).getText() is "-3" and ctx.expr(1).getText() is "(n+1)" visitExpr(ctx) negation where ctx.expr(0).getText() is "3" visitExpr(ctx) numeric literal where ctx.NUM().getText() is "3" visitExpr(ctx) parentheses where ctx.expr(0).getText() is "n+1" visitExpr(ctx) addition where ctx.expr(0).getText() is "n" and ctx.expr(1).getText() is "1" visitExpr(ctx) variable where ctx.ID().getText() is "n" visitExpr(ctx) numeric literal where ctx.NUM().getText() is "1"
--==-=-=--
--=-=-=--
--===-=-= Content-Type: application/pgp-signature; name="signature.asc"
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2
iQEcBAEBCAAGBQJW50vIAAoJEGuLsz1PMbCLX9EH/39nA9Mt4hKyyMr3/PB5i84e er+i+nQ9PvFItrB+haMBigH956S3ah/sE0gyhErXWK3OMCctmigZWpdLQWxpfbYZ E68cMb0tUXZIZXM4CKxQHqtZ5XL1vq/qOXoY3Z9Sd+lDYDbiwTZEdFbuVYXW89Yf nymFGnoZ1z3kDGnTxvlZwKtMDC1Bd59O0XAbvO3K5a3mKntOvAieS02G10DXa8AN 9YpeDEZRWe33j4XXhFI4LoZX37KXgm6P8F4+67pOYh4oUHpNFvyz3WAzmpOSzbce MISwvA4NCFuUiSZkKumQLXV2Rdshnw5PoT5h3q7fQ9Gor4Y/fc8fbwY85pmxhRQ= =AITe -----END PGP SIGNATURE----- --===-=-=--
--===============1958295665== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline
_______________________________________________ Learn mailing list Learn-at-nylxs.com http://lists.mrbrklyn.com/mailman/listinfo/learn
--===============1958295665==--
|
|