Java Doc for Action.java in  » Parser » Rats-Parser-Generators » xtc » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Parser » Rats Parser Generators » xtc.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


xtc.util.Action

Action
public interface Action (Code)
The interface to all actions. An action implements a computation that takes a single argument and produces a single result. Both argument and result have the same type so that actions can be trivially composed with each other.

Actions help in producing a left-recursive AST, even though the productions generating the individual AST nodes are right-recursive (as left-recursion is generally illegal for Rats!' grammars). The basic idea is to create a Pairlist of actions during the right-recursion and then apply the actions onto the semantic value of the base case.

To illustrate this use of actions, consider the grammar rule for logical and expressions in C:

 logical-and-expression :
 bitwise-or-expression
 logical-and-expression && bitwise-or-expression
 
Since this grammar rule is left-recursive, it cannot directly be converted into the corresponding Rats! production and must be rewritten as a right-recursion. At the same time, the corresponding AST should still be left-recursive, as the logical and operator is left-associative.

Using actions and xtc.tree.GNode generic nodes as semantic values, the corresponding right-recursive productions can be written as follows:

 Node LogicalAndExpression =
 base:BitwiseOrExpression list:LogicalAndExpressionTail*
 { yyValue = apply(list, base); }
 ;
 Action<Node> LogicalAndExpressionTail =
 "&&":Symbol right:BitwiseOrExpression
 { yyValue = new Action<Node>() {
 public Node run(Node left) {
 return GNode.create("LogicalAndExpression", left, right);
 }};
 }
 ;
 
The semantic action for the LogicalAndExpression production relies on an apply() helper method, which can be written as following:
 <T> T apply(Pair<Action<T>> actions, T seed) {
 while (! actions.isEmpty()) {
 seed    = actions.head().run(seed);
 actions = actions.tail();
 }
 return seed;
 }
 
In detail, the LogicalAndExpressionTail production recognizes logical and operators followed by the right operands. By using an action as its semantic value, the production delays the actual construction of the corresponding generic node. Once all logical and operators and the corresponding bitwise or expressions have been parsed, the semantic action for the LogicalAndExpression production applies the actions and creates a left-recursive AST. Note that this example assumes that the production for bitwise or expressions also has a generic node as its semantic value. Further note that, if there is no logical and operator in the input, this example simply passes the semantic value of the single bitwise or expression through, which is the desired behavior as it leaves the AST unmodified. Finally, note that direct left recursions may appear in generic productions, as Rats! automatically transforms them into the corresponding right-recursions while also creating left-recursive semantic values with the help of actions.
author:
   Robert Grimm
version:
   $Revision: 1.10 $




Method Summary
 Trun(T arg)
     Perform this action.
Parameters:
  arg - The argument.



Method Detail
run
T run(T arg)(Code)
Perform this action.
Parameters:
  arg - The argument. The result.



www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.