input
stringlengths
10
828
output
stringlengths
5
107
protected void gen header println antlr generated file resulting from grammar antlr tool grammar file println diagnostic output println println terence parr mage lang institute println with john lilley empathy software println antlr version antlr tool version 1996 1997 println println header action println this action will appear at the top of all generated files tabs print action behavior get header action tabs println end of header action println
generate a header that is common to all txt files
private void gen error catch for element alternative element el if el get label null return string r el enclosing rule name if grammar instanceof lexer grammar r code generator encode lexer rule name el enclosing rule name rule symbol rs rule symbol grammar get symbol r if rs null antlr tool panic enclosing rule not found exception spec ex rs block find exception spec el get label if ex null tabs println gen error handler ex
close the try block and generate catch phrases
public void gen alternative block blk if debug code generator system out println gen blk println gen block preamble blk gen block init action blk tell ast generation to build subrule result string save current astresult current astresult if blk get label null current astresult blk get label boolean ok grammar the llk analyzer deterministic blk java block finishing info how to finish gen common block blk true gen block finish how to finish throw no viable println restore previous ast generation current astresult save current astresult
generate code for the given grammar element
public void gen char range element r if r get label null syntactic pred level 0 println r get label lt1 value boolean flag grammar instanceof lexer grammar save text r get auto gen type grammar element auto gen bang if flag println save index text length println match range r begin text r end text if flag println text set length save index
generate code for the given grammar element
public void map to token symbol string name token symbol sym system out println map to token symbol name sym table put name sym
map a label or string to an existing token symbol
public void gen alternative block blk if debug code generator system out println gen blk println tabs gen block preamble blk gen block init action blk tell ast generation to build subrule result string save current astresult current astresult if blk get label null current astresult blk get label boolean ok grammar the llk analyzer deterministic blk csharp block finishing info how to finish gen common block blk true gen block finish how to finish throw no viable tabs println restore previous ast generation current astresult save current astresult
generate code for the given grammar element
public void gen char range element r if r get label null syntactic pred level 0 println r get label lt1 value boolean flag grammar instanceof lexer grammar save text r get auto gen type grammar element auto gen bang if flag println save index text length println match range octal to unicode r begin text octal to unicode r end text if flag println text length save index
generate code for the given grammar element
public void gen lexer grammar g throws ioexception if debugging create a new sempred vector for this grammar if g debugging output sem preds new vector set grammar g if grammar instanceof lexer grammar antlr tool panic internal error generating lexer gen body g
generate the lexer csharp file
public void gen parser grammar g throws ioexception if debugging set up a new vector to keep track of sempred strings for this grammar if g debugging output sem preds new vector set grammar g if grammar instanceof parser grammar antlr tool panic internal error generating parser gen body g
generate the parser csharp file
public void gen token range element r gen error try for element r if r get label null syntactic pred level 0 println r get label lt1 value ast gen element ast r match println match range octal to unicode r begin text octal to unicode r end text gen error catch for element r
generate code for the given grammar element
public void gen tree walker grammar g throws ioexception sas debugging stuff removed for now set grammar g if grammar instanceof tree walker grammar antlr tool panic internal error generating tree walker gen body g
generate the tree parser csharp file
protected void gen bitsets vector bitset list int max vocabulary println for int i 0 i bitset list size i bit set p bit set bitset list element at i ensure that generated bit set is large enough for vocabulary p grow to include max vocabulary gen bit set p i
generate all the bitsets to be used in the parser or lexer
protected void gen header println antlr tool version antlr tool file minus path antlr tool grammar file grammar get class name java
generate a header that is common to all java files
public string get astcreate string string str system out println get ast create string str str grammar token manager token defined str if using custom ast return static cast labeled element asttype ast factory create static cast namespace antlr ref ast str else return ast factory create str
get a string for an expression to generate creating of an ast node
public string get range expression int k int elems if elements are range elems antlr tool panic get range expression called with non range int begin elems 0 int end elems elems length 1 return lookahead string k get value string begin lookahead string k get value string end
return an expression for testing a contiguous renage of elements
protected string extract id of action token t return extract id of action t get text t get line t get column
get the identifier portion of an argument action token
protected string extract type of action token t return extract type of action t get text t get line t get column
get the type string out of an argument action token
public string get astcreate string grammar atom atom string ast ctor args system out println get astcreate string atom ast ctor args if atom null atom get astnode type null they specified a type either on the reference or in tokens section return atom get astnode type ast factory create ast ctor args atom get astnode type else must be an action or something since not referencing an atom return get astcreate string ast ctor args
get a string for an expression to generate creating of an ast node
public string process string for astconstructor string str return str
process a string for an simple expression for use in xx action
protected void gen sem pred map enumeration e sem preds elements println private string sem pred names tabs while e has more elements println e next element tabs println
write an array of strings which are the semantic predicate
protected string get lookahead test expression alternative alt int max depth int depth alt lookahead depth if depth grammar analyzer nondeterministic if the decision is nondeterministic do the best we can ll k any predicates that are around will be generated later depth grammar maxk if max depth 0 empty lookahead can result from alt with sem pred that can see end of token e g a pred a return true return get lookahead test expression alt cache depth
generate a lookahead test expression for an alternate
public void system string cmd runtime rt runtime get runtime try log cmd process proc null if os starts with windows assume unixen if not windoze windoze tool expands proc rt exec new string sh c cmd else proc rt exec cmd stream scarfer stderr scarfer new stream scarfer proc get error stream stderr this stream scarfer stdout scarfer new stream scarfer proc get input stream stdout this stderr scarfer start stdout scarfer start int exit val proc wait for catch exception e error cannot exec cmd e
a portable system command execution routine that logs stdout stderr
public void stdout string s system out println s
stdout from executing sub tools
public void stderr string s system err println s
stderr from executing sub tools
public void jar tool tool if root is valid antlrdir tool return string buffer cmd new string buffer 2000 cmd append jar cvf root jar name for int i 0 i srcdir length i cmd append root srcdir i class tool system cmd to string
jar up all the
public string escape string string s string retval new string for int i 0 i s length i retval escape char s char at i false return retval
converts a string into a representation that can be use as a literal
public string literal string string s return escape string s
converts a string into a string literal
public void do everything wrapper string args int exit code do everything args system exit exit code
perform processing on the grammar file
public void error string s string file int line int column has error true system err println file line formatter get formatter get format string file line column s
issue an error with line number information
public object factory string p class c object o null try c class for name p get class def o c new instance make a new one catch exception e either class not found class is interface abstract or class or initializer is not accessible warning can t create an object of type p return null return o
when we are 1
public string get language make grammar behavior if gen diagnostics return diagnostic if gen html return html if gen doc book return doc book return behavior language
determine the language used for this run of antlr
public print writer open output file string f throws ioexception return new print writer new preserving file writer output dir system get property file separator f
this method is used by all code generators to create new output
public void fatal error string message system err println message system exit 1
an error occured that should stop the tool from doing any work
public void panic fatal error panic
issue an unknown fatal error
public void panic string s fatal error panic s
issue a fatal error message
public string path to file string f string separator system get property file separator int end of path f last index of separator if end of path 1 no path use current directory return system get property file separator return f substring 0 end of path 1
given a filename strip off the directory prefix if any
public void tool error string s system err println error s
issue an error used for general tool errors not for grammar stuff
public void warning string s system err println warning s
issue a warning
public void warning string s string file int line int column system err println file line formatter get formatter get format string file line column warning s
issue a warning with line number information
public void warning string s string file int line int column if s null s length 0 panic bad multi line message to tool warning system err println file line formatter get formatter get format string file line column warning s 0 for int i 1 i s length i system err println file line formatter get formatter get format string file line column s i
issue a warning with line number information
public void set name space string name if null name space name space new name space string utils strip front back name
support c c namespaces for now
public void set tool antlr tool tool if antlr tool null antlr tool tool else throw new illegal state exception antlr tool already registered
in order to make it so existing subclasses dont break we wont require
public void report error string s if get tool null get tool error s get filename 1 1 else super report error s
delegates the error message to the tool if any was registered via
public void report error recognition exception e if get tool null get tool error e get error message e get filename e get line e get column else super report error e
delegates the error message to the tool if any was registered via
public void report warning string s if get tool null get tool warning s get filename 1 1 else super report warning s
delegates the warning message to the tool if any was registered via
public string get message string mesg unexpected char i m trying to mirror a change in the c stuff but java seems to lack something isprint ish so we do it manually this is probably to restrictive if found char found char mesg mesg found char mesg else mesg 0x int t int found char 4 if t 10 mesg char t 0x30 else mesg char t 0x37 t int found char 0x f if t 10 mesg char t 0x30 else mesg char t 0x37 return mesg
returns a clean error message no line number column information
public ast create return create token invalid type
create a new empty ast node if the user did not specify
public ast create int type string txt string class name ast t create class name if t null t initialize type txt return t
create an ast node with the token type and text passed in but
public ast create ast tr if tr null return null create null null ast t create tr get type if t null t initialize tr return t
create a new empty ast node if the user did not specify
public ast create token tok string class name ast t create using ctor tok class name if t null t initialize tok return t
antlr generates reference to this when you reference a token
public ast dup ast t if t null return null ast dup t create t get class dup t initialize t return dup t
copy a single node with same java ast objec type
public void set astnode type string t set astnode class t
specify the type of node to create during tree building
public void error string e system err println e
to change where error messages go can subclass override this method
public void gen rule ref element rr rule symbol rs rule symbol grammar get symbol rr target rule generate the actual rule description print a href grammar get class name html rr target rule print rr target rule print a rk leave out args if rr args null print rr args print
generate code for the given grammar element
public int get number of children base ast t this down int n 0 if t null n 1 while t right null t t right n return n return n
how many children does this node have
public astenumeration find all ast target vector roots new vector 10 the empty tree cannot result in an enumeration if target null return null do work for find all roots target false find all matches recursively return new astenumerator roots
walk the tree looking for all exact subtree matches
public astenumeration find all partial ast sub vector roots new vector 10 the empty tree cannot result in an enumeration if sub null return null do work for find all roots sub true find all matches recursively return new astenumerator roots
walk the tree looking for all subtrees
public void set type int ttype
set the token type for this node
public string get message if token null return unexpected token token get text must a tree parser error if token null if node tree parser astnull return unexpected end of subtree return unexpected ast node node to string
returns a clean error message no line number column information
public void reset n markers 0 marker offset 0 num to consume 0 queue reset
reset the input buffer
public void process arguments string args for int i 0 i args length i if args i equals trace trace rules true antlr tool set arg ok i else if args i equals trace parser trace rules true antlr tool set arg ok i else if args i equals debug debugging output true antlr tool set arg ok i
process command line arguments
public void process arguments string args for int i 0 i args length i if args i equals trace trace rules true antlr tool set arg ok i else if args i equals trace lexer trace rules true antlr tool set arg ok i else if args i equals debug debugging output true antlr tool set arg ok i
process command line arguments
public void show command boolean show f show command show
sets if the command should be printed out first before executing
public int wait and read output stream out output stream err if f show command print command line f command args out if f process null return illegal command process closure closure new process closure f process out err closure run blocking a blocking call return ok
reads output form the process to the streams
public void run non blocking thread group group new thread group cbuilder f counter input stream stdin f process get input stream input stream stderr f process get error stream f output reader new reader thread group output reader stdin f output f error reader new reader thread group error reader stderr f error f output reader start f error reader start
live links the launched process with the configured in out streams using
public void terminate if f process null f process destroy f process null
forces the termination the launched process
public void write int b throws ioexception byte buf new byte 1 buf 0 byte b write buf 0 1
implementation of read for the input stream
public void close throws ioexception if fd 1 return int status close0 fd if status 1 throw new ioexception close error non nls 1 fd 1
close the reader
public int read throws ioexception byte b new byte 1 if 1 read b 0 1 return 1 return int b 0
implementation of read for the input stream
public void close throws ioexception if fd 1 return int status close0 fd if status 1 throw new ioexception close error fd 1
close the reader
public void add item system menu item item add item item 1
add an item on the end of the system menu
public void add item system menu item item int position add item item position win32 mf byposition
add an item on the specified position of the system menu
public void reset menu check state extension get system menu shell handle true item map clear h menu extension get system menu shell handle false
reset the shells system menu this operation will remove all of the
public void show menu int pos extension get message pos show menu new point short pos 0x ffff short pos 16
show the system menu
public string get text if value of manager id null return manager get text id return text
get menu items text
public void set image image image this image image if value of manager id null manager set image id image
set specified image on the menu item
public void set text string text this text text if value of manager id null manager set text id text
set specified text on the menu item
public void set selection boolean selected this selected selected if manager get item id null manager set selection id selected
set menu item whether be checked
public boolean get selection if manager get item id null return manager get selection id else return selected
get the menu item checked status
public integer get id return new integer id
get the menu item id
public void fire selected event event event for int i 0 i listeners size i listener listeners get i handle event event
fire menu item selected event
public void set enabled boolean enabled this enabled enabled if manager get item id null manager set enabled id enabled
set the menu item whether enabled
public boolean is enabled if manager get item id null return manager get enabled id else return enabled
get the menu item enabled status
public void dispose if value of manager id null manager remove item id listeners clear
dispose the menu item
public boolean is global only return global only
returns true if the hook descriptor which is determinated by this
public void install if is installed throw new illegal state exception hook is already installed event loop new hook event loop events thread new thread event loop events thread start
installs the hook
public int get message if struct null return struct message else return 0
specifies the message
public void install boolean global if is installed throw new illegal state exception hook is already installed event loop new hook event loop global events thread new thread event loop events thread start
installs the hook
public int get param l if struct null return struct param l else return 0
specifies additional information about the message
public int get param h if struct null return struct param h else return 0
specifies additional information about the message
public int get time if struct null return struct time else return 0
specifies the time at which the message was posted
public void uninstall if is installed throw new illegal state exception hook is not installed event loop uninstall try events thread join events thread null catch interrupted exception e e print stack trace
uninstalls the hook
public int get hwnd if struct null return struct hwnd else return 0
handle to the window to which the message was posted
public event msg get struct return new event msg struct
get eventmsg struct from hook proc
public long get virtual key code return get wparam
specifies the virtual key code
public int get repeat count flag set flag set new flag set get lparam return flag set get bits 0 15
specifies the repeat count
public int get scan code flag set flag set new flag set get lparam return flag set get bits 16 23
specifies the scan code
public boolean is alt pressed flag set flag set new flag set get lparam return flag set get bit 29
specifies the context code
public boolean get previous state flag set flag set new flag set get lparam return flag set get bit 30
specifies the previous key state
public boolean get transition state flag set flag set new flag set get lparam return flag set get bit 31
specifies the transition state