110 likes | 126 Views
XAWK is an XML processing language inspired by AWK, offering pattern matching for XML elements, associative arrays, control statements, and more. This language features implicit promotion, concatenation, and easy XML processing. Learn through examples and implementation details.
E N D
XAWK John Cieslewicz Shi Tak Man Gabriela Cretu Prashant Puri
Introduction • XAWK is inspired by the AWK programming language by Aho, et al. • Goal: Provide an easy to use XML processing language whose syntax resembles AWK • Instead of matching text patterns (AWK), match patterns of XML elements (XAWK).
XML Pattern Matching (XPath) Associative Arrays Undeclared variables OK! Fully featured control statements for(x in array) Implicit promotion between strings and numbers Concatenation by juxtaposition Language Features
Example XML File <students> <group name=“XAWK”> <student fname=“John” mt=“45.0”/> <student fname=“Gabriela” mt=“88.9”/> <student fname=“Shi Tak” mt=“66.6”/> <student fname=“Prashant” mt=“67”/> </group> </students>
Example Grading Program /doc(“roster.xml”)/students/group/{ print “Group name: “, @name; /student/{ print “Student name: “, CA[“fname”]; print “Midterm score: “, @mt; } }
Grading with Descendent /doc(“roster.xml”)//group/{ print “Group name: “, @name; /student/{ print “Student name: “, CA[“fname”]; print “Midterm score: “, @mt; } }
More Language Examples j =0; /student/{ name = @fname; studentName[j] = name; grades[name] = @mt; grades[name] += @final; j++; }
XAWK Testing • ant build file for robust compiling and test execution • Shell script for testing ‘failure cases’ • Test cases: • Pattern matching • Control statements • Arrays • Mathematical and Relational Operators • Concatenation • Promotion
Conclusion and Lessons Learned • Antlr can be made to do just about anything, but you might need a crowbar • Testing is very important • Coding in pairs helps catch errors and solve problems • Constant code refactoring keeps it clear and clean • Get to work early, make a good plan